Make bulk_free() go faster

This commit is contained in:
Justine Tunney 2024-12-23 20:14:01 -08:00
parent 624573207e
commit c8e10eef30
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
13 changed files with 54 additions and 36 deletions

View file

@ -62,11 +62,6 @@
#include "locks.inc"
#include "chunks.inc"
#include "headfoot.inc"
#if ONLY_MSPACES
#include "threaded.inc"
#endif
#include "global.inc"
#include "system.inc"
#include "hooks.inc"
@ -74,6 +69,11 @@
#include "indexing.inc"
#include "binmaps.inc"
#include "runtimechecks.inc"
#if ONLY_MSPACES
#include "threaded.inc"
#endif
#include "init.inc"
#include "debuglib.inc"
#include "statistics.inc"

View file

@ -61,8 +61,23 @@ int dlmalloc_trim(size_t pad) {
}
size_t dlbulk_free(void *array[], size_t nelem) {
for (size_t i = 0; i < nelem; ++i)
mspace_free(0, array[i]);
size_t j = 0;
mstate msp = (mstate)-1;
for (size_t i = 0; i < nelem; ++i) {
mstate next;
if (array[i]) {
next = get_mstate_for(mem2chunk(array[i]));
if (next != msp) {
if (j)
mspace_bulk_free(msp, array, j);
msp = next;
j = 0;
}
array[j++] = array[i];
}
}
if (j)
mspace_bulk_free(msp, array, j);
return 0;
}