terminal: RefCountedSet should call deleted on upsert

This commit is contained in:
Mitchell Hashimoto
2024-07-03 19:03:25 -07:00
parent d1f41e2035
commit 548850e453

View File

@ -476,9 +476,13 @@ pub fn RefCountedSet(
/// is ignored and the existing item's ID is returned. /// is ignored and the existing item's ID is returned.
fn upsert(self: *Self, base: anytype, value: T, new_id: Id, ctx: Context) Id { fn upsert(self: *Self, base: anytype, value: T, new_id: Id, ctx: Context) Id {
// If the item already exists, return it. // If the item already exists, return it.
// TODO: we should probably call deleted here on value since if (self.lookup(base, value, ctx)) |id| {
// we're using the value already in the map // Notify the context that the value is "deleted" because
if (self.lookup(base, value, ctx)) |id| return id; // we're reusing the existing value in the set. This allows
// callers to clean up any resources associated with the value.
if (comptime @hasDecl(Context, "deleted")) ctx.deleted(value);
return id;
}
const table = self.table.ptr(base); const table = self.table.ptr(base);
const items = self.items.ptr(base); const items = self.items.ptr(base);