Make Document::idmap store a Vec.

This commit is contained in:
Ms2ger 2014-04-26 10:37:27 +02:00
parent 50ab85f3ee
commit 7346992981

View file

@ -58,7 +58,7 @@ pub struct Document {
pub node: Node,
pub reflector_: Reflector,
pub window: JS<Window>,
pub idmap: HashMap<DOMString, ~[JS<Element>]>,
pub idmap: HashMap<DOMString, Vec<JS<Element>>>,
pub implementation: Option<JS<DOMImplementation>>,
pub content_type: DOMString,
pub encoding_name: DOMString,
@ -232,11 +232,9 @@ impl Document {
// http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
pub fn GetElementById(&self, id: DOMString) -> Option<JS<Element>> {
// TODO: "in tree order, within the context object's tree"
// http://dom.spec.whatwg.org/#dom-document-getelementbyid.
match self.idmap.find_equiv(&id) {
None => None,
Some(ref elements) => Some(elements[0].clone()),
Some(ref elements) => Some(elements.get(0).clone()),
}
}
@ -679,7 +677,7 @@ impl Document {
for node in root.traverse_preorder() {
match ElementCast::to(&node) {
Some(elem) => {
if elements[head] == elem {
if elements.get(head) == &elem {
head = head + 1;
}
if new_node == node || head == elements.len() {
@ -694,6 +692,6 @@ impl Document {
},
None => (),
}
self.idmap.insert(id, ~[element.clone()]);
self.idmap.insert(id, vec!(element.clone()));
}
}