Skip to content

Commit

Permalink
Move init check earlier. This will allow for zero init of the global …
Browse files Browse the repository at this point in the history
…allocator.
  • Loading branch information
mjp41 committed Mar 20, 2020
1 parent 04e74c4 commit f2da4ff
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/mem/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1062,17 +1062,21 @@ namespace snmalloc

Slab* slab;

if (likely(!sl.is_empty()))
if (likely(!NeedsInitialisation(this)))
{
stats().sizeclass_alloc(sizeclass);
if (likely(!sl.is_empty()))
{
stats().sizeclass_alloc(sizeclass);

SlabLink* link = sl.get_next();
slab = get_slab(link);
auto& ffl = small_fast_free_lists[sizeclass];
return slab->alloc<zero_mem>(
sl, ffl, rsize, large_allocator.memory_provider);
SlabLink* link = sl.get_next();
slab = get_slab(link);
auto& ffl = small_fast_free_lists[sizeclass];
return slab->alloc<zero_mem>(
sl, ffl, rsize, large_allocator.memory_provider);
}
return small_alloc_rare<zero_mem, allow_reserve>(sizeclass);
}
return small_alloc_rare<zero_mem, allow_reserve>(sizeclass);
return small_alloc_first_alloc<zero_mem, allow_reserve>(sizeclass);
}

/**
Expand All @@ -1083,12 +1087,8 @@ namespace snmalloc
template<ZeroMem zero_mem, AllowReserve allow_reserve>
SNMALLOC_SLOW_PATH void* small_alloc_rare(sizeclass_t sizeclass)
{
if (likely(!NeedsInitialisation(this)))
{
stats().sizeclass_alloc(sizeclass);
return small_alloc_new_free_list<zero_mem, allow_reserve>(sizeclass);
}
return small_alloc_first_alloc<zero_mem, allow_reserve>(sizeclass);
stats().sizeclass_alloc(sizeclass);
return small_alloc_new_free_list<zero_mem, allow_reserve>(sizeclass);
}

/**
Expand Down

0 comments on commit f2da4ff

Please sign in to comment.