aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2015-10-24 17:25:09 -0500
committerbors-servo <lbergstrom+bors@mozilla.com>2015-10-24 17:25:09 -0500
commit3b50f219631ee8b8746199ef2bc1d60c716295ea (patch)
tree8c3b201702d0487c25288754fbd1673d518ada0d
parent354e75a447c8afc7757d0340c03119de853110f5 (diff)
parent48ea5959c72d3c5b4b47262f51ea9b25a963a255 (diff)
downloadservo-3b50f219631ee8b8746199ef2bc1d60c716295ea.tar.gz
servo-3b50f219631ee8b8746199ef2bc1d60c716295ea.zip
Auto merge of #8181 - frewsxcv:no-alloc-get-element-by-id, r=nox
Remove unnecessary allocation with getElementById <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8181) <!-- Reviewable:end -->
-rw-r--r--components/script/dom/document.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index e8c23b5994c..23d455a1903 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -419,7 +419,7 @@ impl Document {
/// Attempt to find a named element in this page's document.
/// https://html.spec.whatwg.org/multipage/#the-indicated-part-of-the-document
pub fn find_fragment_node(&self, fragid: &str) -> Option<Root<Element>> {
- self.GetElementById(fragid.to_owned()).or_else(|| {
+ self.get_element_by_id(&Atom::from_slice(fragid)).or_else(|| {
let check_anchor = |node: &HTMLAnchorElement| {
let elem = node.upcast::<Element>();
elem.get_attribute(&ns!(""), &atom!("name")).map_or(false, |attr| {
@@ -1146,6 +1146,10 @@ impl Document {
new_doc
})
}
+
+ fn get_element_by_id(&self, id: &Atom) -> Option<Root<Element>> {
+ self.idmap.borrow().get(&id).map(|ref elements| (*elements)[0].root())
+ }
}
@@ -1264,8 +1268,7 @@ impl DocumentMethods for Document {
// https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
fn GetElementById(&self, id: DOMString) -> Option<Root<Element>> {
- let id = Atom::from_slice(&id);
- self.idmap.borrow().get(&id).map(|ref elements| (*elements)[0].root())
+ self.get_element_by_id(&Atom::from_slice(&id))
}
// https://dom.spec.whatwg.org/#dom-document-createelement