From 12dd1e9c8a19ba85761a89b30a4aa652f234e89a Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Tue, 27 May 2025 20:25:18 +0200 Subject: [PATCH] refactor: convert editor.matches to an ArrayListUnmanaged --- src/tui/editor.zig | 12 ++++++------ src/tui/inspector_view.zig | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/tui/editor.zig b/src/tui/editor.zig index 4c07840..c7d2be5 100644 --- a/src/tui/editor.zig +++ b/src/tui/editor.zig @@ -59,7 +59,7 @@ pub const Match = struct { has_selection: bool = false, style: ?Widget.Theme.Style = null, - const List = std.ArrayList(?Self); + const List = std.ArrayListUnmanaged(?Self); const Self = @This(); pub fn from_selection(sel: Selection) Self { @@ -454,7 +454,7 @@ pub const Editor = struct { .animation_last_time = time.microTimestamp(), .cursels = CurSel.List.init(allocator), .cursels_saved = CurSel.List.init(allocator), - .matches = Match.List.init(allocator), + .matches = .empty, .enable_terminal_cursor = tui.config().enable_terminal_cursor, .render_whitespace = from_whitespace_mode(tui.config().whitespace_mode), .diagnostics = .empty, @@ -469,7 +469,7 @@ pub const Editor = struct { self.diagnostics.deinit(self.allocator); if (self.syntax) |syn| syn.destroy(tui.query_cache()); self.cursels.deinit(); - self.matches.deinit(); + self.matches.deinit(self.allocator); self.handlers.deinit(); self.logger.deinit(); if (self.buffer) |p| self.buffer_manager.retire(p, meta.items); @@ -1749,7 +1749,7 @@ pub const Editor = struct { } fn cancel_all_matches(self: *Self) void { - self.matches.clearAndFree(); + self.matches.clearAndFree(self.allocator); } pub fn clear_matches(self: *Self) void { @@ -4993,7 +4993,7 @@ pub const Editor = struct { var match: Match = .{ .begin = .{ .row = begin_line, .col = begin_pos }, .end = .{ .row = end_line, .col = end_pos } }; if (match.end.eql(self.get_primary().cursor)) match.has_selection = true; - (self.matches.addOne() catch return).* = match; + (self.matches.addOne(self.allocator) catch return).* = match; } fn find_selection_match(self: *const Self, sel: Selection) ?*Match { @@ -5415,7 +5415,7 @@ pub const Editor = struct { }; switch (self.matches.items.len) { 0 => { - (self.matches.addOne() catch return).* = match; + (self.matches.addOne(self.allocator) catch return).* = match; }, 1 => { self.matches.items[0] = match; diff --git a/src/tui/inspector_view.zig b/src/tui/inspector_view.zig index e7590fd..967648e 100644 --- a/src/tui/inspector_view.zig +++ b/src/tui/inspector_view.zig @@ -88,7 +88,7 @@ fn dump_highlight(self: *Self, range: syntax.Range, scope: []const u8, id: u32, if (self.theme) |theme| match.style = .{ .bg = theme.editor_gutter_modified.fg }; switch (self.editor.matches.items.len) { 0 => { - (self.editor.matches.addOne() catch return).* = match; + (self.editor.matches.addOne(self.editor.allocator) catch return).* = match; update_match = .add; }, 1 => { @@ -116,7 +116,7 @@ fn dump_highlight(self: *Self, range: syntax.Range, scope: []const u8, id: u32, var match_parent = ed.Match.from_selection(sel_parent); if (self.theme) |theme| match_parent.style = .{ .bg = theme.editor_gutter_added.fg }; switch (update_match) { - .add => (self.editor.matches.addOne() catch return).* = match_parent, + .add => (self.editor.matches.addOne(self.editor.allocator) catch return).* = match_parent, .set => self.editor.matches.items[1] = match_parent, .no => {}, }