From 247e4ac3cc18a1a29bc180873b7b9f946f515212 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Sun, 18 Feb 2024 10:14:39 +0100 Subject: dwarf: optimize dwarf parsing for speed This code is run when printing a stack trace in a debug executable, so it has to be fast even without compiler optimizations. Adding a `@panic` to the top of `main` and running an x86_64 backend compiled compiler goes from `1m32.773s` to `0m3.232s`. --- lib/std/io/fixed_buffer_stream.zig | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'lib/std/io/fixed_buffer_stream.zig') 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 { -- cgit v1.2.3