avoid redundant checks for large realloc
This commit is contained in:
parent
eb7ced7781
commit
d18b05eaf4
6
malloc.c
6
malloc.c
@ -847,8 +847,9 @@ EXPORT void *h_realloc(void *old, size_t size) {
|
||||
size_t old_rounded_size = PAGE_CEILING(old_size);
|
||||
size_t rounded_size = PAGE_CEILING(size);
|
||||
|
||||
if (size > max_slab_size_class) {
|
||||
// in-place shrink
|
||||
if (size < old_size && size > max_slab_size_class) {
|
||||
if (size < old_size) {
|
||||
void *new_end = (char *)old + rounded_size;
|
||||
if (memory_map_fixed(new_end, old_guard_size)) {
|
||||
return NULL;
|
||||
@ -868,7 +869,6 @@ EXPORT void *h_realloc(void *old, size_t size) {
|
||||
}
|
||||
|
||||
// in-place growth
|
||||
if (size > old_size) {
|
||||
void *guard_end = (char *)old + old_rounded_size + old_guard_size;
|
||||
size_t extra = rounded_size - old_rounded_size;
|
||||
if (!memory_remap((char *)old + old_rounded_size, old_guard_size, old_guard_size + extra)) {
|
||||
@ -886,7 +886,6 @@ EXPORT void *h_realloc(void *old, size_t size) {
|
||||
return old;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t copy_size = size < old_size ? size : old_size;
|
||||
if (copy_size >= mremap_threshold) {
|
||||
@ -913,6 +912,7 @@ EXPORT void *h_realloc(void *old, size_t size) {
|
||||
return new;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void *new = allocate(size);
|
||||
if (new == NULL) {
|
||||
|
Loading…
Reference in New Issue
Block a user