aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/cssstyledeclaration.rs
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2016-04-04 21:14:57 +0200
committerSimon Sapin <simon.sapin@exyr.org>2016-05-25 09:25:33 +0200
commitdc829da07ef705f5b76315c9746362a7c18354c9 (patch)
tree688809c4492adbeae1acf4d577a82a53dc0b4a9c /components/script/dom/cssstyledeclaration.rs
parent7d7aac212b34d7875f1a179a2cd8ef08233bda6c (diff)
downloadservo-dc829da07ef705f5b76315c9746362a7c18354c9.tar.gz
servo-dc829da07ef705f5b76315c9746362a7c18354c9.zip
Less cloning and dynamic dispatch.
Diffstat (limited to 'components/script/dom/cssstyledeclaration.rs')
-rw-r--r--components/script/dom/cssstyledeclaration.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs
index bcc569cbf6d..410c7757f5b 100644
--- a/components/script/dom/cssstyledeclaration.rs
+++ b/components/script/dom/cssstyledeclaration.rs
@@ -13,6 +13,8 @@ use dom::element::{Element, StylePriority};
use dom::node::{Node, window_from_node};
use dom::window::Window;
use std::ascii::AsciiExt;
+use std::cell::Ref;
+use std::slice;
use string_cache::Atom;
use style::parser::ParserContextExtraData;
use style::properties::{PropertyDeclaration, Shorthand};
@@ -140,14 +142,22 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
// Step 2.2.2 & 2.2.3
match declaration {
- Some(declaration) => list.push(declaration.clone()),
+ Some(declaration) => list.push(declaration),
None => return DOMString::new(),
}
}
// Step 2.3
- let mut list = list.iter().map(|x| &*x);
- let serialized_value = shorthand.serialize_shorthand_to_string(&mut list);
+ // Work around closures not being Clone
+ #[derive(Clone)]
+ struct Map<'a, 'b: 'a>(slice::Iter<'a, Ref<'b, PropertyDeclaration>>);
+ impl<'a, 'b> Iterator for Map<'a, 'b> {
+ type Item = &'a PropertyDeclaration;
+ fn next(&mut self) -> Option<Self::Item> {
+ self.0.next().map(|r| &**r)
+ }
+ }
+ let serialized_value = shorthand.serialize_shorthand_to_string(Map(list.iter()));
return DOMString::from(serialized_value);
}