Converted serialization methods to implement the to_css trait, writing to string buffers to save string allocations for every result

This commit is contained in:
David Raifaizen 2016-03-26 11:02:34 -04:00 committed by Simon Sapin
parent 0985d7563f
commit 51e642e875
4 changed files with 132 additions and 46 deletions

View file

@ -10,7 +10,7 @@ use dom::bindings::js::{JS, Root};
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::str::DOMString;
use dom::element::{Element, StylePriority};
use dom::node::{Node, NodeDamage, window_from_node};
use dom::node::{Node, window_from_node};
use dom::window::Window;
use std::ascii::AsciiExt;
use string_cache::Atom;
@ -147,7 +147,8 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
// Step 2.3
let list = list.iter().map(|x| &*x).collect::<Vec<_>>();
return DOMString::from(shorthand.serialize_shorthand(&list));
let serialized_value = shorthand.serialize_shorthand_to_string(&list);
return DOMString::from(serialized_value);
}
// Step 3 & 4

View file

@ -5,7 +5,7 @@
//! Element nodes.
use app_units::Au;
use cssparser::Color;
use cssparser::{Color, ToCss};
use devtools_traits::AttrInfo;
use dom::activation::Activatable;
use dom::attr::AttrValue;
@ -699,12 +699,10 @@ impl Element {
}
fn sync_property_with_attrs_style(&self) {
let style_str = if let &Some(ref declarations) = &*self.style_attribute().borrow() {
declarations.serialize()
let mut style_str = String::new();
if let &Some(ref declarations) = &*self.style_attribute().borrow() {
declarations.to_css(&mut style_str).unwrap();
}
else {
String::new()
};
let new_style = AttrValue::String(style_str);