| ... | ... | @@ -454,6 +454,14 @@ pub fn safeAdd(a: anytype, b: anytype) @TypeOf(a) { |
| 454 | 454 | return a - @as(@TypeOf(a), @intCast(-@as(OneBiggerInt(@TypeOf(b)), b))); |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | /// Allows u32 + i16 to work |
| 458 | pub fn safeAddWrap(a: anytype, b: anytype) @TypeOf(a) { |
| 459 | if (b >= 0) { |
| 460 | return a +% @as(@TypeOf(a), @intCast(b)); |
| 461 | } |
| 462 | return a -% @as(@TypeOf(a), @intCast(-@as(OneBiggerInt(@TypeOf(b)), b))); |
| 463 | } |
| 464 | |
| 457 | 465 | pub fn readBytesAlloc(reader: anytype, alloc: std.mem.Allocator, len: usize) ![]u8 { |
| 458 | 466 | var list = std.ArrayListUnmanaged(u8){}; |
| 459 | 467 | try list.ensureTotalCapacityPrecise(alloc, len); |