mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
RefCountedSet: add some missing context delete callbacks
This commit is contained in:
@ -232,10 +232,16 @@ pub fn RefCountedSet(
|
|||||||
// we're reusing the existing value in the set. This allows
|
// we're reusing the existing value in the set. This allows
|
||||||
// callers to clean up any resources associated with the value.
|
// callers to clean up any resources associated with the value.
|
||||||
if (comptime @hasDecl(Context, "deleted")) ctx.deleted(value);
|
if (comptime @hasDecl(Context, "deleted")) ctx.deleted(value);
|
||||||
|
|
||||||
items[id].meta.ref += 1;
|
items[id].meta.ref += 1;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Notify the context that the value is "deleted" if we return an
|
||||||
|
// error. This allows callers to clean up any resources associated
|
||||||
|
// with the value.
|
||||||
|
errdefer if (comptime @hasDecl(Context, "deleted")) ctx.deleted(value);
|
||||||
|
|
||||||
// If the item doesn't exist, we need an available ID.
|
// If the item doesn't exist, we need an available ID.
|
||||||
if (self.next_id >= self.layout.cap) {
|
if (self.next_id >= self.layout.cap) {
|
||||||
// Arbitrarily chosen, threshold for rehashing.
|
// Arbitrarily chosen, threshold for rehashing.
|
||||||
@ -279,6 +285,8 @@ pub fn RefCountedSet(
|
|||||||
pub fn addWithIdContext(self: *Self, base: anytype, value: T, id: Id, ctx: Context) AddError!?Id {
|
pub fn addWithIdContext(self: *Self, base: anytype, value: T, id: Id, ctx: Context) AddError!?Id {
|
||||||
const items = self.items.ptr(base);
|
const items = self.items.ptr(base);
|
||||||
|
|
||||||
|
assert(id > 0);
|
||||||
|
|
||||||
if (id < self.next_id) {
|
if (id < self.next_id) {
|
||||||
if (items[id].meta.ref == 0) {
|
if (items[id].meta.ref == 0) {
|
||||||
self.deleteItem(base, id, ctx);
|
self.deleteItem(base, id, ctx);
|
||||||
@ -291,6 +299,11 @@ pub fn RefCountedSet(
|
|||||||
|
|
||||||
return if (added_id == id) null else added_id;
|
return if (added_id == id) null else added_id;
|
||||||
} else if (ctx.eql(value, items[id].value)) {
|
} else if (ctx.eql(value, items[id].value)) {
|
||||||
|
// Notify the context that the value is "deleted" because
|
||||||
|
// 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);
|
||||||
|
|
||||||
items[id].meta.ref += 1;
|
items[id].meta.ref += 1;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -501,6 +514,7 @@ pub fn RefCountedSet(
|
|||||||
// we're reusing the existing value in the set. This allows
|
// we're reusing the existing value in the set. This allows
|
||||||
// callers to clean up any resources associated with the value.
|
// callers to clean up any resources associated with the value.
|
||||||
if (comptime @hasDecl(Context, "deleted")) ctx.deleted(value);
|
if (comptime @hasDecl(Context, "deleted")) ctx.deleted(value);
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user