MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / ObjectPool_NewItem

Function ObjectPool_NewItem

src/util/object_pool/object_pool.c:94–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

92}
93
94void *ObjectPool_NewItem(ObjectPool *pool) {
95 // Reuse a deleted item if one is available.
96 if(array_len(pool->deletedIdx)) return _ObjectPool_ReuseItem(pool);
97
98 // Make sure we have room for a new item.
99 if(pool->itemCount >= pool->itemCap) {
100 // Double the capacity of the pool.
101 _ObjectPool_AddBlocks(pool, ITEM_COUNT_TO_BLOCK_COUNT(pool->itemCap));
102 }
103
104 // Get the index of the new allocation.
105 ObjectID idx = pool->itemCount;
106 pool->itemCount++;
107
108 Block *block = GET_ITEM_BLOCK(pool, idx);
109 uint pos = ITEM_POSITION_WITHIN_BLOCK(idx);
110
111 // Retrieve a pointer to the item's header.
112 unsigned char *item_header = block->data + (pos * block->itemSize);
113 unsigned char *item = ITEM_FROM_HEADER(item_header);
114 ITEM_ID(item) = idx; // Set the item ID.
115
116 return item;
117}
118
119void ObjectPool_DeleteItem(ObjectPool *pool, void *item) {
120 ASSERT(pool != NULL);

Callers 3

test_objectPoolAddItemFunction · 0.85

Calls 3

array_lenFunction · 0.85
_ObjectPool_ReuseItemFunction · 0.85
_ObjectPool_AddBlocksFunction · 0.85

Tested by 2

test_objectPoolAddItemFunction · 0.68