From d14b4cf0684fe40987f24df1849fee618423150e Mon Sep 17 00:00:00 2001 From: Qwerasd Date: Tue, 18 Nov 2025 15:42:29 -0700 Subject: [PATCH] perf: streamline RefCountedSet lookup + add branch hint to insert --- src/terminal/ref_counted_set.zig | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/terminal/ref_counted_set.zig b/src/terminal/ref_counted_set.zig index 25512bdaf..3d0dd469a 100644 --- a/src/terminal/ref_counted_set.zig +++ b/src/terminal/ref_counted_set.zig @@ -515,14 +515,11 @@ pub fn RefCountedSet( return null; } - // We don't bother checking dead items. - if (item.meta.ref == 0) { - continue; - } - // If the item is a part of the same probe sequence, - // we check if it matches the value we're looking for. + // we make sure it's not dead and then check to see + // if it matches the value we're looking for. if (item.meta.psl == i and + item.meta.ref > 0 and ctx.eql(value, item.value)) { return id; @@ -594,6 +591,11 @@ pub fn RefCountedSet( // unless its ID is greater than the one we're // given (i.e. prefer smaller IDs). if (item.meta.ref == 0) { + // Dead items aren't super common relative + // to other places to insert/swap the held + // item in to the set. + @branchHint(.unlikely); + if (comptime @hasDecl(Context, "deleted")) { // Inform the context struct that we're // deleting the dead item's value for good.