If all the memory we're accessing is in the same 4GB segment of the address
space, this eliminates calls to sb_find_leaf altogether, a significant
savings. But even if we're ranging across more than one segment, this
should win in cases that have some degree of access locality.
#if SIZEOF_SIZE_T > 4
{
Size highbits = p >> 32;
+ static Size last_highbits = 0;
+ static sb_lookup_leaf *last_leaf = NULL;
- leaf = sb_find_leaf(highbits, false);
+ /* Quick test to see if we're in same range as before. */
+ if (last_highbits == highbits && last_leaf != NULL)
+ leaf = last_leaf;
+ else
+ {
+ leaf = sb_find_leaf(highbits, false);
- /* No lookup table for this 4GB range? OK, no matching region. */
- if (leaf == NULL)
- return NULL;
+ /* No lookup table for this 4GB range? OK, no matching region. */
+ if (leaf == NULL)
+ return NULL;
+
+ /* Remember results of this lookup for next time. */
+ last_highbits = highbits;
+ last_leaf = leaf;
+ }
}
#else
leaf = &lookup_root_leaf;