From d853aaba65089fd2b207527ccf588b912fe0e3ad Mon Sep 17 00:00:00 2001 From: vectorijk Date: Fri, 14 Aug 2015 00:10:49 -0700 Subject: [PATCH 1/2] remove unused static collection --- components/script/dom/htmlcollection.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/components/script/dom/htmlcollection.rs b/components/script/dom/htmlcollection.rs index fcf9de175f8..7f65ad18056 100644 --- a/components/script/dom/htmlcollection.rs +++ b/components/script/dom/htmlcollection.rs @@ -25,8 +25,7 @@ pub trait CollectionFilter : JSTraceable { #[derive(JSTraceable)] #[must_root] pub enum CollectionTypeId { - Static(Vec>), - Live(JS, Box) + Live(JS, Box) } #[dom_struct] @@ -181,7 +180,6 @@ impl<'a> HTMLCollectionMethods for &'a HTMLCollection { // https://dom.spec.whatwg.org/#dom-htmlcollection-length fn Length(self) -> u32 { match self.collection { - CollectionTypeId::Static(ref elems) => elems.len() as u32, CollectionTypeId::Live(ref root, ref filter) => { let root = root.root(); HTMLCollection::traverse(root.r()) @@ -195,8 +193,6 @@ impl<'a> HTMLCollectionMethods for &'a HTMLCollection { fn Item(self, index: u32) -> Option> { let index = index as usize; match self.collection { - CollectionTypeId::Static(ref elems) => elems - .get(index).map(|t| t.root()), CollectionTypeId::Live(ref root, ref filter) => { let root = root.root(); HTMLCollection::traverse(root.r()) @@ -215,11 +211,6 @@ impl<'a> HTMLCollectionMethods for &'a HTMLCollection { // Step 2. match self.collection { - CollectionTypeId::Static(ref elems) => elems.iter() - .map(|elem| elem.root()) - .find(|elem| { - elem.r().get_string_attribute(&atom!("name")) == key || - elem.r().get_string_attribute(&atom!("id")) == key }), CollectionTypeId::Live(ref root, ref filter) => { let root = root.root(); HTMLCollection::traverse(root.r()) From 59d704b53fd8fbd21fa95539b6b592147dd0dc2f Mon Sep 17 00:00:00 2001 From: vectorijk Date: Sat, 15 Aug 2015 02:49:15 -0700 Subject: [PATCH 2/2] turn enum into struct pub enum CollectionTypeId -> pub struct Collection --- components/script/dom/htmlcollection.rs | 58 +++++++++++-------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/components/script/dom/htmlcollection.rs b/components/script/dom/htmlcollection.rs index 7f65ad18056..bbac05d5b97 100644 --- a/components/script/dom/htmlcollection.rs +++ b/components/script/dom/htmlcollection.rs @@ -24,27 +24,25 @@ pub trait CollectionFilter : JSTraceable { #[derive(JSTraceable)] #[must_root] -pub enum CollectionTypeId { - Live(JS, Box) -} +pub struct Collection(JS, Box); #[dom_struct] #[derive(HeapSizeOf)] pub struct HTMLCollection { reflector_: Reflector, #[ignore_heap_size_of = "Contains a trait object; can't measure due to #6870"] - collection: CollectionTypeId, + collection: Collection, } impl HTMLCollection { - fn new_inherited(collection: CollectionTypeId) -> HTMLCollection { + fn new_inherited(collection: Collection) -> HTMLCollection { HTMLCollection { reflector_: Reflector::new(), collection: collection, } } - pub fn new(window: &Window, collection: CollectionTypeId) -> Root { + pub fn new(window: &Window, collection: Collection) -> Root { reflect_dom_object(box HTMLCollection::new_inherited(collection), GlobalRef::Window(window), HTMLCollectionBinding::Wrap) } @@ -53,7 +51,7 @@ impl HTMLCollection { impl HTMLCollection { pub fn create(window: &Window, root: &Node, filter: Box) -> Root { - HTMLCollection::new(window, CollectionTypeId::Live(JS::from_ref(root), filter)) + HTMLCollection::new(window, Collection(JS::from_ref(root), filter)) } fn all_elements(window: &Window, root: &Node, @@ -178,31 +176,28 @@ impl HTMLCollection { impl<'a> HTMLCollectionMethods for &'a HTMLCollection { // https://dom.spec.whatwg.org/#dom-htmlcollection-length + #[allow(unrooted_must_root)] fn Length(self) -> u32 { - match self.collection { - CollectionTypeId::Live(ref root, ref filter) => { - let root = root.root(); - HTMLCollection::traverse(root.r()) - .filter(|element| filter.filter(element.r(), root.r())) - .count() as u32 - } - } + let Collection(ref root, ref filter) = self.collection; + let root = root.root(); + HTMLCollection::traverse(root.r()) + .filter(|element| filter.filter(element.r(), root.r())) + .count() as u32 } // https://dom.spec.whatwg.org/#dom-htmlcollection-item + #[allow(unrooted_must_root)] fn Item(self, index: u32) -> Option> { let index = index as usize; - match self.collection { - CollectionTypeId::Live(ref root, ref filter) => { - let root = root.root(); - HTMLCollection::traverse(root.r()) - .filter(|element| filter.filter(element.r(), root.r())) - .nth(index) - } - } + let Collection(ref root, ref filter) = self.collection; + let root = root.root(); + HTMLCollection::traverse(root.r()) + .filter(|element| filter.filter(element.r(), root.r())) + .nth(index) } // https://dom.spec.whatwg.org/#dom-htmlcollection-nameditem + #[allow(unrooted_must_root)] fn NamedItem(self, key: DOMString) -> Option> { // Step 1. if key.is_empty() { @@ -210,16 +205,13 @@ impl<'a> HTMLCollectionMethods for &'a HTMLCollection { } // Step 2. - match self.collection { - CollectionTypeId::Live(ref root, ref filter) => { - let root = root.root(); - HTMLCollection::traverse(root.r()) - .filter(|element| filter.filter(element.r(), root.r())) - .find(|elem| { - elem.r().get_string_attribute(&atom!("name")) == key || - elem.r().get_string_attribute(&atom!("id")) == key }) - } - } + let Collection(ref root, ref filter) = self.collection; + let root = root.root(); + HTMLCollection::traverse(root.r()) + .filter(|element| filter.filter(element.r(), root.r())) + .find(|elem| { + elem.r().get_string_attribute(&atom!("name")) == key || + elem.r().get_string_attribute(&atom!("id")) == key}) } // https://dom.spec.whatwg.org/#dom-htmlcollection-item