@@ -168,6 +168,7 @@ Format of STDIN stream:
168168#include "dir.h"
169169#include "run-command.h"
170170#include "packfile.h"
171+ #include "mem-pool.h"
171172
172173#define PACK_ID_BITS 16
173174#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
@@ -209,26 +210,6 @@ struct last_object {
209210 unsigned no_swap : 1 ;
210211};
211212
212- struct mp_block {
213- struct mp_block * next_block ;
214- char * next_free ;
215- char * end ;
216- uintmax_t space [FLEX_ARRAY ]; /* more */
217- };
218-
219- struct mem_pool {
220- struct mp_block * mp_block ;
221-
222- /*
223- * The amount of available memory to grow the pool by.
224- * This size does not include the overhead for the mp_block.
225- */
226- size_t block_alloc ;
227-
228- /* The total amount of memory allocated by the pool. */
229- size_t pool_alloc ;
230- };
231-
232213struct atom_str {
233214 struct atom_str * next_atom ;
234215 unsigned short str_len ;
@@ -647,55 +628,6 @@ static unsigned int hc_str(const char *s, size_t len)
647628 return r ;
648629}
649630
650- static struct mp_block * mem_pool_alloc_block (struct mem_pool * mem_pool , size_t block_alloc )
651- {
652- struct mp_block * p ;
653-
654- mem_pool -> pool_alloc += sizeof (struct mp_block ) + block_alloc ;
655- p = xmalloc (st_add (sizeof (struct mp_block ), block_alloc ));
656- p -> next_block = mem_pool -> mp_block ;
657- p -> next_free = (char * )p -> space ;
658- p -> end = p -> next_free + block_alloc ;
659- mem_pool -> mp_block = p ;
660-
661- return p ;
662- }
663-
664- static void * mem_pool_alloc (struct mem_pool * mem_pool , size_t len )
665- {
666- struct mp_block * p ;
667- void * r ;
668-
669- /* round up to a 'uintmax_t' alignment */
670- if (len & (sizeof (uintmax_t ) - 1 ))
671- len += sizeof (uintmax_t ) - (len & (sizeof (uintmax_t ) - 1 ));
672-
673- for (p = mem_pool -> mp_block ; p ; p = p -> next_block )
674- if (p -> end - p -> next_free >= len )
675- break ;
676-
677- if (!p ) {
678- if (len >= (mem_pool -> block_alloc / 2 )) {
679- mem_pool -> pool_alloc += len ;
680- return xmalloc (len );
681- }
682-
683- p = mem_pool_alloc_block (mem_pool , mem_pool -> block_alloc );
684- }
685-
686- r = p -> next_free ;
687- p -> next_free += len ;
688- return r ;
689- }
690-
691- static void * mem_pool_calloc (struct mem_pool * mem_pool , size_t count , size_t size )
692- {
693- size_t len = st_mult (count , size );
694- void * r = mem_pool_alloc (mem_pool , len );
695- memset (r , 0 , len );
696- return r ;
697- }
698-
699631static char * pool_strdup (const char * s )
700632{
701633 size_t len = strlen (s ) + 1 ;
0 commit comments