aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom
diff options
context:
space:
mode:
authorIszak Bryan <iszak.bryan@gmail.com>2016-01-03 01:07:00 +0000
committerIszak Bryan <iszak.bryan@gmail.com>2016-01-03 01:07:00 +0000
commitc02a56c01aef48e09722c19979ab60e504184192 (patch)
tree299c650f59f66a292744f385f19466878bdda995 /components/script/dom
parent618c1070cce287e3f23818259b35989b7fcf7d48 (diff)
downloadservo-c02a56c01aef48e09722c19979ab60e504184192.tar.gz
servo-c02a56c01aef48e09722c19979ab60e504184192.zip
Optimise get_root_element for elements in documents
Diffstat (limited to 'components/script/dom')
-rw-r--r--components/script/dom/element.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index 5d500b9ef75..85dcaab67ed 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -12,6 +12,7 @@ use dom::attr::AttrValue;
use dom::attr::{Attr, AttrHelpersForLayout};
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods;
+use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
use dom::bindings::codegen::Bindings::ElementBinding;
use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
@@ -772,11 +773,18 @@ impl Element {
// https://html.spec.whatwg.org/multipage/#root-element
pub fn get_root_element(&self) -> Root<Element> {
- self.upcast::<Node>()
- .inclusive_ancestors()
- .filter_map(Root::downcast)
- .last()
- .expect("We know inclusive_ancestors will return `self` which is an element")
+ if self.node.is_in_doc() {
+ self.upcast::<Node>()
+ .owner_doc()
+ .GetDocumentElement()
+ .unwrap()
+ } else {
+ self.upcast::<Node>()
+ .inclusive_ancestors()
+ .filter_map(Root::downcast)
+ .last()
+ .expect("We know inclusive_ancestors will return `self` which is an element")
+ }
}
// https://dom.spec.whatwg.org/#locate-a-namespace-prefix