diff options
author | Nicholas Clark <nick@ccl4.org> | 2010-08-20 11:25:50 +0100 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2010-08-20 17:34:39 +0100 |
commit | 29657bb6c05aaef4172308097542f56a92e02a08 (patch) | |
tree | 7bb1617504da0ddc2506d9a4bbc9a1b28b4f6c0c /sv.c | |
parent | eaeb1e7f3008ef8680fd7726bb124dac46e2f98c (diff) | |
download | perl-29657bb6c05aaef4172308097542f56a92e02a08.tar.gz |
Refactor the loop of S_more_bodies() to be (hopefully) clearer.
Diffstat (limited to 'sv.c')
-rw-r--r-- | sv.c | 19 |
1 files changed, 14 insertions, 5 deletions
@@ -1053,7 +1053,9 @@ S_more_bodies (pTHX_ const svtype sv_type) start = (char*) Perl_get_arena(aTHX_ arena_size, sv_type); - end = start + arena_size - 2 * body_size; + /* Get the address of the byte after the end of the last body we can fit. + Remember, this is integer division: */ + end = start + arena_size / body_size * body_size; /* computed count doesnt reflect the 1st slot reservation */ #if defined(MYMALLOC) || defined(HAS_MALLOC_GOOD_SIZE) @@ -1072,14 +1074,21 @@ S_more_bodies (pTHX_ const svtype sv_type) #endif *root = (void *)start; - while (start <= end) { + while (1) { + /* Where the next body would start: */ char * const next = start + body_size; + + if (next >= end) { + /* This is the last body: */ + assert(next == end); + + *(void **)start = 0; + return *root; + } + *(void**) start = (void *)next; start = next; } - *(void **)start = 0; - - return *root; } /* grab a new thing from the free list, allocating more if necessary. |