diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/arena.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/arena.c b/src/arena.c index bd93eeb..d02694d 100644 --- a/src/arena.c +++ b/src/arena.c | |||
| @@ -23,6 +23,12 @@ chunk_size (struct arena__chunk *chunk) | |||
| 23 | return chunk->end - chunk->data; | 23 | return chunk->end - chunk->data; |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | static size_t | ||
| 27 | chunk_used (struct arena__chunk *chunk) | ||
| 28 | { | ||
| 29 | return chunk->free - chunk->data; | ||
| 30 | } | ||
| 31 | |||
| 26 | static struct arena__chunk * | 32 | static struct arena__chunk * |
| 27 | new_chunk (size_t size) | 33 | new_chunk (size_t size) |
| 28 | { | 34 | { |
| @@ -206,11 +212,13 @@ arena__coalesce_from_fast (ARENA arena, struct arena__checkpoint checkpoint, | |||
| 206 | 212 | ||
| 207 | // copy old chunks into new chunk | 213 | // copy old chunks into new chunk |
| 208 | size_t other_size = checkpoint.tail->free - checkpoint.free; | 214 | size_t other_size = checkpoint.tail->free - checkpoint.free; |
| 209 | memcpy (chunk->free, checkpoint.free, other_size); | 215 | if (other_size) { |
| 210 | chunk->free += other_size; | 216 | memcpy (chunk->free, checkpoint.free, other_size); |
| 217 | chunk->free += other_size; | ||
| 218 | } | ||
| 211 | for (struct arena__chunk *other_chunk = checkpoint.tail->next; | 219 | for (struct arena__chunk *other_chunk = checkpoint.tail->next; |
| 212 | other_chunk; other_chunk = other_chunk->next) { | 220 | other_chunk; other_chunk = other_chunk->next) { |
| 213 | other_size = chunk_size (other_chunk); | 221 | other_size = chunk_used (other_chunk); |
| 214 | memcpy (chunk->free, other_chunk->data, other_size); | 222 | memcpy (chunk->free, other_chunk->data, other_size); |
| 215 | chunk->free += other_size; | 223 | chunk->free += other_size; |
| 216 | } | 224 | } |
