mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-09 15:19:07 +00:00
Fix reset.
This commit is contained in:
parent
74b9139bc3
commit
50b16ef544
1 changed files with 7 additions and 8 deletions
|
|
@ -126,19 +126,18 @@ pub fn Extra(comptime Item: type, comptime pool_options: Options) type {
|
||||||
///
|
///
|
||||||
/// NOTE: If `mode` is `free_all`, the function will always return `true`.
|
/// NOTE: If `mode` is `free_all`, the function will always return `true`.
|
||||||
pub fn reset(self: *Pool, allocator: Allocator, mode: ResetMode) bool {
|
pub fn reset(self: *Pool, allocator: Allocator, mode: ResetMode) bool {
|
||||||
|
self.free_list = .{};
|
||||||
var arena = self.arena_state.promote(allocator);
|
var arena = self.arena_state.promote(allocator);
|
||||||
defer self.arena_state = arena.state;
|
const arena_mode: std.heap.ArenaAllocator.ResetMode = switch (mode) {
|
||||||
|
|
||||||
const ArenaResetMode = std.heap.ArenaAllocator.ResetMode;
|
|
||||||
const arena_mode = switch (mode) {
|
|
||||||
.free_all => .free_all,
|
.free_all => .free_all,
|
||||||
.retain_capacity => .retain_capacity,
|
.retain_capacity => .retain_capacity,
|
||||||
.retain_with_limit => |limit| ArenaResetMode{ .retain_with_limit = limit * item_size },
|
.retain_with_limit => |limit| .{ .retain_with_limit = limit * item_size },
|
||||||
};
|
};
|
||||||
self.free_list = .{};
|
const arena_result = arena.reset(arena_mode);
|
||||||
if (!arena.reset(arena_mode)) return false;
|
self.arena_state = arena.state;
|
||||||
|
if (!arena_result) return false;
|
||||||
// When the backing arena allocator is being reset to
|
// When the backing arena allocator is being reset to
|
||||||
// a capacity greater than 0, then its internals consists
|
// a capacity greater than 0, then its internals consist
|
||||||
// of a *single* buffer node of said capacity. This means,
|
// of a *single* buffer node of said capacity. This means,
|
||||||
// we can safely pre-heat without causing additional allocations.
|
// we can safely pre-heat without causing additional allocations.
|
||||||
const arena_capacity = arena.queryCapacity() / item_size;
|
const arena_capacity = arena.queryCapacity() / item_size;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue