MCPcopy Create free account
hub / github.com/bytedance/bolt / allocateFromFreeList

Method allocateFromFreeList

bolt/common/memory/HashStringAllocator.cpp:416–441  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

414}
415
416HashStringAllocator::Header* FOLLY_NULLABLE
417HashStringAllocator::allocateFromFreeList(
418 int32_t preferredSize,
419 bool mustHaveSize,
420 bool isFinalSize,
421 int32_t freeListIndex) {
422 auto* item = free_[freeListIndex].next();
423 if (item == &free_[freeListIndex]) {
424 return nullptr;
425 }
426 auto found = headerOf(item);
427 BOLT_CHECK(
428 found->isFree() && (!mustHaveSize || found->size() >= preferredSize));
429 --numFree_;
430 freeBytes_ -= found->size() + sizeof(Header);
431 removeFromFreeList(found);
432 auto next = found->next();
433 if (next) {
434 next->clearPreviousFree();
435 }
436 cumulativeBytes_ += found->size();
437 if (isFinalSize) {
438 freeRestOfBlock(found, preferredSize);
439 }
440 return found;
441}
442
443void HashStringAllocator::free(Header* _header) {
444 Header* header = _header;

Callers

nothing calls this directly

Calls 4

isFreeMethod · 0.80
clearPreviousFreeMethod · 0.80
nextMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected