From cf2b9c76edf4088504fae19a5c7c0b059847a79c Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Fri, 6 Dec 2024 21:07:14 +0100 Subject: [PATCH] fix: limit ripgrep processing to 1000 lines of output More is not really useful and potentially very laggy. --- src/ripgrep.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ripgrep.zig b/src/ripgrep.zig index 3d25689..663303d 100644 --- a/src/ripgrep.zig +++ b/src/ripgrep.zig @@ -161,15 +161,22 @@ const Process = struct { fn handle_terminated(self: *Process) !void { const output = try self.output.toOwnedSlice(); + var count: usize = 0; var it = std.mem.splitScalar(u8, output, '\n'); while (it.next()) |json| { if (json.len == 0) continue; var msg_buf: [tp.max_message_size]u8 = undefined; const msg: tp.message = .{ .buf = try cbor.fromJson(json, &msg_buf) }; try self.dispatch(msg); + count += 1; + if (count > 1000) break; } try self.parent.send(.{ self.tag, "done" }); - self.logger.print("found {d} matches", .{self.match_count}); + if (count > 1000) { + self.logger.print("found more than {d} matches", .{self.match_count}); + } else { + self.logger.print("found {d} matches", .{self.match_count}); + } } fn dispatch(self: *Process, m: tp.message) !void {