diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-02-18 12:41:37 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-18 12:41:37 -0800 |
| commit | 7775e46e8179fd1f4e27ca45fc211ac2e23a6969 (patch) | |
| tree | f4b479b4deb3ad2b3c0440f936107adffa81b80c /lib/std/io | |
| parent | 3cafb9655a754743da695af41ef635b79d066127 (diff) | |
| parent | 247e4ac3cc18a1a29bc180873b7b9f946f515212 (diff) | |
| download | zig-7775e46e8179fd1f4e27ca45fc211ac2e23a6969.tar.gz zig-7775e46e8179fd1f4e27ca45fc211ac2e23a6969.zip | |
Merge pull request #18983 from jacobly0/dwarf-rewrite
dwarf: optimize dwarf parsing for speed
Diffstat (limited to 'lib/std/io')
| -rw-r--r-- | lib/std/io/fixed_buffer_stream.zig | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/lib/std/io/fixed_buffer_stream.zig b/lib/std/io/fixed_buffer_stream.zig index f62ac415a4..8b64923fe7 100644 --- a/lib/std/io/fixed_buffer_stream.zig +++ b/lib/std/io/fixed_buffer_stream.zig @@ -62,11 +62,7 @@ pub fn FixedBufferStream(comptime Buffer: type) type { if (bytes.len == 0) return 0; if (self.pos >= self.buffer.len) return error.NoSpaceLeft; - const n = if (self.pos + bytes.len <= self.buffer.len) - bytes.len - else - self.buffer.len - self.pos; - + const n = @min(self.buffer.len - self.pos, bytes.len); @memcpy(self.buffer[self.pos..][0..n], bytes[0..n]); self.pos += n; @@ -76,7 +72,7 @@ pub fn FixedBufferStream(comptime Buffer: type) type { } pub fn seekTo(self: *Self, pos: u64) SeekError!void { - self.pos = if (std.math.cast(usize, pos)) |x| @min(self.buffer.len, x) else self.buffer.len; + self.pos = @min(std.math.lossyCast(usize, pos), self.buffer.len); } pub fn seekBy(self: *Self, amt: i64) SeekError!void { |
