Use swap_remove when unrooting DOM objects. (#36617)

Profiling from #36609 showed this is an easy win. Ordering of our root
list does not matter, so swap_remove is a constant time operation
compared to a linear time one that caused memmove to appear in profiles
with lots of unrooting.

Testing: Existing WPT tests will cover this change.
Fixes: Part of #36609.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Josh Matthews 2025-04-19 16:18:01 -04:00 committed by GitHub
parent c792e6db7c
commit fad5447838
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -412,7 +412,7 @@ impl RootCollection {
.rposition(|r| std::ptr::addr_eq(*r as *const (), object as *const ()))
{
Some(idx) => {
roots.remove(idx);
roots.swap_remove(idx);
},
None => panic!("Can't remove a root that was never rooted!"),
}