bitmap_tree_link_element first splays the tree to ensure that the
root is a neighbour of the element that we want to insert. But the
callers have already done the same kind of splay operation in order
to prove that no existing element has the required index.
Repeating the operation isn't free. For example, if the first splay
operation leaves the left neighbour N in the root, the second splay
operation would need to search N->right->left (N->next->prev),
and similarly in reverse for a right neighbour.
This gives a reproducible 20% improvement in an artificial test that
inserted 2,000,000 pseudo-random elements (keeping the same sequence
for all tests).
gcc/
* bitmap.cc (bitmap_tree_link_element): Require callers to have
done a splay operation. Avoid doing another one here.
return t;
}
-/* Link bitmap element E into the current bitmap splay tree. */
+/* Link bitmap element E into the current bitmap splay tree. The caller
+ must have called bitmap_tree_find_element first, which guarantees that
+ the current root should become a neighbor of E. */
static inline void
bitmap_tree_link_element (bitmap head, bitmap_element *e)
{
- if (head->first == NULL)
+ bitmap_element *t = head->first;
+ if (t == NULL)
e->prev = e->next = NULL;
else
{
- bitmap_element *t = bitmap_tree_splay (head, head->first, e->indx);
if (e->indx < t->indx)
{
e->prev = t->prev;