Fix slab count not being properly updated

This commit is contained in:
kayomn 2023-06-04 14:00:21 +00:00
parent 155645a308
commit 5500de299b
2 changed files with 21 additions and 11 deletions

View File

@ -52,17 +52,6 @@ pub fn Map(comptime index_int: std.builtin.Type.Int, comptime Value: type) type
entry.value = value; entry.value = value;
} }
///
/// Fetches the value referenced by `index` in `self`, returning it.
///
pub fn fetch(self: *Self, index: Index) Value {
const entry = &self.table[index];
debug.assert(entry.* == .value);
return entry.value;
}
/// ///
/// Deinitializes `self` and sets it to an invalid state, freeing all memory allocated by `allocator`. /// Deinitializes `self` and sets it to an invalid state, freeing all memory allocated by `allocator`.
/// ///
@ -81,6 +70,17 @@ pub fn Map(comptime index_int: std.builtin.Type.Int, comptime Value: type) type
self.free_index = 0; self.free_index = 0;
} }
///
/// Fetches the value referenced by `index` in `self`, returning it.
///
pub fn fetch(self: *Self, index: Index) Value {
const entry = &self.table[index];
debug.assert(entry.* == .value);
return entry.value;
}
/// ///
/// Attempts to grow the internal buffer of `self` by `growth_amount` using `allocator`. /// Attempts to grow the internal buffer of `self` by `growth_amount` using `allocator`.
/// ///
@ -147,12 +147,20 @@ pub fn Map(comptime index_int: std.builtin.Type.Int, comptime Value: type) type
debug.assert(entry.* == .free_index); debug.assert(entry.* == .free_index);
self.count += 1;
self.free_index = entry.free_index; self.free_index = entry.free_index;
entry.* = .{.value = value}; entry.* = .{.value = value};
return entry_index; return entry_index;
} }
///
/// Returns `true` if `self` contains no values, otherwise `false`.
///
pub fn is_empty(self: Self) bool {
return self.count == 0;
}
/// ///
/// Removes the value referenced by `index` from `self`. /// Removes the value referenced by `index` from `self`.
/// ///
@ -161,6 +169,7 @@ pub fn Map(comptime index_int: std.builtin.Type.Int, comptime Value: type) type
debug.assert(entry.* == .value); debug.assert(entry.* == .value);
self.count -= 1;
entry.* = .{.free_index = self.free_index}; entry.* = .{.free_index = self.free_index};
self.free_index = index; self.free_index = index;
} }

View File

@ -183,6 +183,7 @@ pub fn deinit(self: *Self) void {
self.interned.deinit(self.allocator); self.interned.deinit(self.allocator);
self.values.deinit(self.allocator); self.values.deinit(self.allocator);
self.calls.deinit(self.allocator); self.calls.deinit(self.allocator);
coral.debug.assert(self.heap.is_empty());
self.heap.deinit(self.allocator); self.heap.deinit(self.allocator);
} }