From cb1caff0181d5e07349b41d273b854967023e1ec Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 3 Jul 2024 16:18:00 -0700 Subject: [PATCH] terminal: refcountedset passes base memory to all context funcs This enables these funcs to access memory offsets that may be present in set items, which is possible since the set itself is in an offset-based structure. --- src/terminal/ref_counted_set.zig | 12 ++++++------ src/terminal/style.zig | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/terminal/ref_counted_set.zig b/src/terminal/ref_counted_set.zig index c6cf12db5..0ea4c5709 100644 --- a/src/terminal/ref_counted_set.zig +++ b/src/terminal/ref_counted_set.zig @@ -264,7 +264,7 @@ pub fn RefCountedSet( self.living += 1; return if (added_id == id) null else added_id; - } else if (self.context.eql(value, items[id].value)) { + } else if (self.context.eql(base, value, items[id].value)) { items[id].meta.ref += 1; return null; @@ -390,7 +390,7 @@ pub fn RefCountedSet( if (comptime @hasDecl(Context, "deleted")) { // Inform the context struct that we're // deleting the dead item's value for good. - self.context.deleted(item.value); + self.context.deleted(base, item.value); } self.psl_stats[item.meta.psl] -= 1; @@ -423,7 +423,7 @@ pub fn RefCountedSet( const table = self.table.ptr(base); const items = self.items.ptr(base); - const hash: u64 = self.context.hash(value); + const hash: u64 = self.context.hash(base, value); for (0..self.max_psl + 1) |i| { const p: usize = @intCast((hash + i) & self.layout.table_mask); @@ -455,7 +455,7 @@ pub fn RefCountedSet( // If the item is a part of the same probe sequence, // we check if it matches the value we're looking for. if (item.meta.psl == i and - self.context.eql(value, item.value)) + self.context.eql(base, value, item.value)) { return id; } @@ -481,7 +481,7 @@ pub fn RefCountedSet( .meta = .{ .psl = 0, .ref = 0 }, }; - const hash: u64 = self.context.hash(value); + const hash: u64 = self.context.hash(base, value); var held_id: Id = new_id; var held_item: *Item = &new_item; @@ -510,7 +510,7 @@ pub fn RefCountedSet( if (comptime @hasDecl(Context, "deleted")) { // Inform the context struct that we're // deleting the dead item's value for good. - self.context.deleted(item.value); + self.context.deleted(base, item.value); } chosen_id = id; diff --git a/src/terminal/style.zig b/src/terminal/style.zig index 430fca214..cce20e711 100644 --- a/src/terminal/style.zig +++ b/src/terminal/style.zig @@ -247,13 +247,15 @@ pub const Set = RefCountedSet( Id, size.CellCountInt, struct { - pub fn hash(self: *const @This(), style: Style) u64 { + pub fn hash(self: *const @This(), base: anytype, style: Style) u64 { _ = self; + _ = base; return style.hash(); } - pub fn eql(self: *const @This(), a: Style, b: Style) bool { + pub fn eql(self: *const @This(), base: anytype, a: Style, b: Style) bool { _ = self; + _ = base; return a.eql(b); } },