Skip to content

Commit

Permalink
Fix Slab.init in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fengb committed Jul 24, 2020
1 parent ea6beae commit 84c33dd
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/slab.zig
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ pub fn ZeeAlloc(comptime conf: Config) type {
element_size: usize,
pad: [conf.slab_size - header_size]u8 align(payload_alignment),

fn init(self: *Slab, element_size: usize) void {
fn init(element_size: usize) Slab {
var result: Slab = undefined;
result.reset(element_size);
return result;
}

fn reset(self: *Slab, element_size: usize) void {
self.next = null;
self.element_size = element_size;

Expand Down Expand Up @@ -222,7 +228,7 @@ pub fn ZeeAlloc(comptime conf: Config) type {
const idx = findSlabIndex(element_size);
const slab = self.slabs[idx] orelse blk: {
const new_slab = try self.backing_allocator.create(Slab);
new_slab.init(element_size);
new_slab.reset(element_size);
self.slabs[idx] = new_slab;
break :blk new_slab;
};
Expand Down

0 comments on commit 84c33dd

Please sign in to comment.