- size_t i;
- alloc_pool_list block_header;
-
- /* Make the block. */
- block = xmalloc (pool->block_size);
- block_header = (alloc_pool_list) block;
- block += align_eight (sizeof (struct alloc_pool_list_def));
-#ifdef GATHER_STATISTICS
- desc->current += pool->block_size;
- if (desc->peak < desc->current)
- desc->peak = desc->current;
-#endif
-
- /* Throw it on the block list. */
- block_header->next = pool->block_list;
- pool->block_list = block_header;
-
- /* Now put the actual block pieces onto the free list. */
- for (i = 0; i < pool->elts_per_block; i++, block += pool->elt_size)
- {
+ char *block;
+ if (!pool->virgin_elts_remaining)
+ {
+ alloc_pool_list block_header;
+
+ /* Make the block. */
+ block = XNEWVEC (char, pool->block_size);
+ block_header = (alloc_pool_list) block;
+ block += align_eight (sizeof (struct alloc_pool_list_def));
+
+ /* Throw it on the block list. */
+ block_header->next = pool->block_list;
+ pool->block_list = block_header;
+
+ /* Make the block available for allocation. */
+ pool->virgin_free_list = block;
+ pool->virgin_elts_remaining = pool->elts_per_block;
+
+ /* Also update the number of elements we have free/allocated, and
+ increment the allocated block count. */
+ pool->elts_allocated += pool->elts_per_block;
+ pool->elts_free += pool->elts_per_block;
+ pool->blocks_allocated += 1;
+ }
+
+
+ /* We now know that we can take the first elt off the virgin list and
+ put it on the returned list. */
+ block = pool->virgin_free_list;
+ header = (alloc_pool_list) USER_PTR_FROM_ALLOCATION_OBJECT_PTR (block);
+ header->next = NULL;