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