| 88 | } |
| 89 | |
| 90 | void *mem_pool_alloc(struct mem_pool *pool, size_t len) |
| 91 | { |
| 92 | struct mp_block *p = NULL; |
| 93 | void *r; |
| 94 | |
| 95 | len = DIV_ROUND_UP(len, GIT_MAX_ALIGNMENT) * GIT_MAX_ALIGNMENT; |
| 96 | |
| 97 | if (pool->mp_block && |
| 98 | pool->mp_block->end - pool->mp_block->next_free >= len) |
| 99 | p = pool->mp_block; |
| 100 | |
| 101 | if (!p) { |
| 102 | if (len >= (pool->block_alloc / 2)) |
| 103 | p = mem_pool_alloc_block(pool, len, pool->mp_block); |
| 104 | else |
| 105 | p = mem_pool_alloc_block(pool, pool->block_alloc, NULL); |
| 106 | } |
| 107 | |
| 108 | r = p->next_free; |
| 109 | p->next_free += len; |
| 110 | return r; |
| 111 | } |
| 112 | |
| 113 | static char *mem_pool_strvfmt(struct mem_pool *pool, const char *fmt, |
| 114 | va_list ap) |