From 8218b463fb0f7a28e4b3645f3566cafcd0fbfc9c Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Sun, 21 Aug 2016 00:28:48 +0200 Subject: [PATCH] Revert "Simplify CSSStyleDeclaration::GetPropertyValue" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 1637b0ba8a66839e3329a3cf552ab2d4fb3c67c6. * As far as I know, `fn` pointers don’t necessarily inline well * Upcoming commits are gonna change this mapping to be less trivial, so this would at least need a new `fn` declaration, making this less of a simplification. --- components/script/dom/cssstyledeclaration.rs | 21 +++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index 1ab80ebf19a..101ac3ef252 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -14,11 +14,12 @@ use dom::element::{Element, StylePriority}; use dom::node::{Node, NodeDamage, window_from_node}; use dom::window::Window; use std::ascii::AsciiExt; -use std::ops::Deref; +use std::cell::Ref; +use std::slice; use string_cache::Atom; use style::parser::ParserContextExtraData; -use style::properties::{Shorthand, is_supported_property}; -use style::properties::{parse_one_declaration, parse_style_attribute}; +use style::properties::{PropertyDeclaration, Shorthand}; +use style::properties::{is_supported_property, parse_one_declaration, parse_style_attribute}; use style::selector_impl::PseudoElement; // http://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface @@ -147,9 +148,19 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration { } } + // Step 2.3 + // 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.0.next().map(|r| &**r) + } + } + // TODO: important is hardcoded to false because method does not implement it yet - let serialized_value = shorthand.serialize_shorthand_value_to_string( - list.iter().map(Deref::deref as fn(_) -> _), false); + let serialized_value = shorthand.serialize_shorthand_value_to_string(Map(list.iter()), false); return DOMString::from(serialized_value); }