- /* Look for entries in free array. */
- freelen = find_free_end(pool, arrsize);
- for (fa_off = 0; fa_off < freelen; fa_off += fa_hdrlen) {
- fa_hdrlen = decode(&off, &free, arr + fa_off);
- off -= MIN_BLOCK_SIZE;
- hdrlen = decode(&len, &free, arr + off);
- if (long_enough(off, len, size, align)) {
- /* Move every successive entry down. */
- memmove(arr + fa_off, arr + fa_off + fa_hdrlen,
- freelen - (fa_off + fa_hdrlen));
- memset(arr + freelen - fa_hdrlen, 0, fa_hdrlen);
- goto found;
+ /* Look for entries in free array, starting from right size up. */
+ for (free_bucket = free_array_off(size);
+ free_bucket < free_array_off(MAX_FREE_CACHED_SIZE);
+ free_bucket += 3) {
+ for (fa_off = free_bucket;
+ fa_off + 3 < free_array_size(poolsize);
+ fa_off += free_array_off(MAX_FREE_CACHED_SIZE)) {
+ off = ((unsigned long)arr[fa_off]) << 16
+ | ((unsigned long)arr[fa_off+1]) << 8
+ | ((unsigned long)arr[fa_off+2]);
+ if (!off)
+ continue;
+
+ hdrlen = decode(&len, &free, arr + off);
+ if (long_enough(off, len, size, align)) {
+ /* Remove it. */
+ memset(&arr[fa_off], 0, 3);
+ goto found;
+ }