diff options
Diffstat (limited to 'src/gui/gui.zig')
| -rw-r--r-- | src/gui/gui.zig | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index d935b5fd..e110b3ab 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -1061,9 +1061,19 @@ const Queue = struct { } fn take(q: *Queue) MessageBatch { + var batch: MessageBatch = .{}; + q.takeInto(&batch); + return batch; + } + + /// `take` into a batch the caller keeps: an idle wakeup copies nothing + /// (the batch is some 20 KB, and was built and returned by value each + /// time). + fn takeInto(q: *Queue, batch: *MessageBatch) void { + batch.len = 0; q.lock(); defer q.unlock(); - var batch: MessageBatch = .{}; + if (q.len == 0 and !q.files_changed and q.completion_len == 0) return; while (q.len > 0) { batch.items[batch.len] = q.items[q.head]; batch.len += 1; @@ -1080,7 +1090,6 @@ const Queue = struct { batch.len += q.completion_len; q.completion_len = 0; std.debug.assert(libc.pthread_cond_broadcast(&q.space) == .SUCCESS); - return batch; } fn discardCompletions(q: *Queue) void { @@ -3999,6 +4008,8 @@ const Shell = struct { ptys: *[pardes.MAX_PANES]?Pty, gens: *[pardes.MAX_PANES]u32, queue: *Queue, + /// What drainQueue takes each wakeup, kept rather than rebuilt. + batch: MessageBatch = .{}, pipe_tasks: *PipeTasks, inotify_fd: c_int, watches: *file_watch.Table, @@ -4153,7 +4164,8 @@ const Shell = struct { s.reconcilePtys(); // After this batch's output, which an exit is told behind. defer s.takeExits(); - var msgs = s.queue.take(); + s.queue.takeInto(&s.batch); + const msgs = &s.batch; var check_files = false; for (msgs.slice()) |m| switch (m) { .output => |o| { |
