diff options
Diffstat (limited to 'test/lspbench.zig')
| -rw-r--r-- | test/lspbench.zig | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/test/lspbench.zig b/test/lspbench.zig index 329e5743..964d3c8c 100644 --- a/test/lspbench.zig +++ b/test/lspbench.zig @@ -147,8 +147,8 @@ pub fn main(init: std.process.Init) !void { } const rss0 = rssKib(); - var results: std.ArrayList(Result) = .empty; - defer results.deinit(gpa); + var results: [anchors.len]Result = undefined; + var result_count: usize = 0; for (anchors) |an| { const path = try std.fs.path.join(gpa, &.{ root, an.file }); @@ -193,11 +193,12 @@ pub fn main(init: std.process.Init) !void { lsp.query(gpa, arena.allocator(), req, &out.writer); break :blk std.mem.indexOf(u8, out.written(), an.expect) != null; }); - try results.append(gpa, r); + results[result_count] = r; + result_count += 1; } const rss = rssKib() -| rss0; - if (json) reportJson(results.items, rss) else reportText(results.items, rss); + if (json) reportJson(results[0..result_count], rss) else reportText(results[0..result_count], rss); } fn runOnce(gpa: std.mem.Allocator, req: lsp.Req, r: *Result) u64 { @@ -264,19 +265,23 @@ fn readZ(gpa: std.mem.Allocator, path: []const u8) ![:0]u8 { const fd = libc.open(path_z, .{ .ACCMODE = .RDONLY }); if (fd < 0) return error.OpenFailed; defer _ = libc.close(fd); - var buf: std.ArrayList(u8) = .empty; - errdefer buf.deinit(gpa); - var chunk: [16384]u8 = undefined; - while (true) { - const n = libc.read(fd, &chunk, chunk.len); + const end = libc.lseek(fd, 0, libc.SEEK.END); + if (end < 0 or libc.lseek(fd, 0, libc.SEEK.SET) < 0) return error.ReadFailed; + const len: usize = @intCast(end); + const buf = try gpa.alloc(u8, len + 1); + errdefer gpa.free(buf); + var filled: usize = 0; + while (filled < len) { + const n = libc.read(fd, buf[filled..].ptr, len - filled); if (n < 0) { if (libc.errno(n) == .INTR) continue; return error.ReadFailed; } - if (n == 0) break; - try buf.appendSlice(gpa, chunk[0..@intCast(n)]); + if (n == 0) return error.UnexpectedEof; + filled += @intCast(n); } - return buf.toOwnedSliceSentinel(gpa, 0); + buf[len] = 0; + return buf[0..len :0]; } /// VmHWM from /proc/self/status — the peak, not the current, so a backend that |
