aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Taubert <tim@timtaubert.de>2014-10-06 03:25:53 +0200
committerTim Taubert <tim@timtaubert.de>2014-10-06 03:28:15 +0200
commita338fbc4b58d937211b08c6fc572037dfcfec53a (patch)
treeb4b8ef20713f63d1db06f6e0bb5e787898113371
parentd23e45fe5db54994f4f3569f8bda1ec5a6121610 (diff)
downloadservo-a338fbc4b58d937211b08c6fc572037dfcfec53a.tar.gz
servo-a338fbc4b58d937211b08c6fc572037dfcfec53a.zip
Use HashMap::find_with_or_insert_with in DocumentHelpers::register_named_element (fixes #3193)
-rw-r--r--components/script/dom/document.rs14
1 files changed, 4 insertions, 10 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 6a39a301b41..1a93b46078a 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -242,11 +242,9 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
let mut idmap = self.idmap.deref().borrow_mut();
- // FIXME https://github.com/mozilla/rust/issues/13195
- // Use mangle() when it exists again.
let root = self.GetDocumentElement().expect("The element is in the document, so there must be a document element.").root();
- match idmap.find_mut(&id) {
- Some(elements) => {
+ idmap.find_with_or_insert_with(id, element,
+ |_key, elements, element| {
let new_node: JSRef<Node> = NodeCast::from_ref(element);
let mut head : uint = 0u;
let root: JSRef<Node> = NodeCast::from_ref(*root);
@@ -265,13 +263,9 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> {
}
}
elements.insert_unrooted(head, &element);
- return;
},
- None => (),
- }
- let mut elements = vec!();
- elements.push_unrooted(&element);
- idmap.insert(id, elements);
+ |_key, element| vec![element.unrooted()]
+ );
}
fn load_anchor_href(self, href: DOMString) {