libsysprof-analyze: short-circuit when address > max

This adds an O(1) check at the head of the lookup to avoid looking at
every RB_RIGHT() in the tree when address falls beyond the upper bound of
the interval tree.
This commit is contained in:
Christian Hergert
2023-05-15 11:20:44 -07:00
parent 00ecc41209
commit 580889f8cb

View File

@ -178,6 +178,13 @@ sysprof_symbol_cache_lookup (SysprofSymbolCache *self,
node = RB_ROOT(&self->head);
/* The root node contains our calculated max as augmented in RBTree.
* Therefore, we can know if @address falls beyond the upper bound
* in O(1) without having to add a branch to the while loop below.
*/
if (node == NULL || node->max < address)
return NULL;
while (node != NULL)
{
g_assert (RB_LEFT(node, link) == NULL ||