[librsvg: 2/4] Remove the style_attr String from ElementInner; fetch it from the Attributes
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 2/4] Remove the style_attr String from ElementInner; fetch it from the Attributes
- Date: Fri, 12 Feb 2021 17:17:23 +0000 (UTC)
commit c854a36b27e6599c1458cff1de9fc39cd3e4a003
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Feb 12 10:40:29 2021 -0600
Remove the style_attr String from ElementInner; fetch it from the Attributes
ElementInner used to keep an element's own copy of the "style"
attribute's value, because attributes were short-lived and only kept
around during parsing. Now that we keep a long-lived Attributes
around, we don't need to keep a copy of that value.
src/element.rs | 26 +++++++-------------------
1 file changed, 7 insertions(+), 19 deletions(-)
---
diff --git a/src/element.rs b/src/element.rs
index 666c0669..61c77504 100644
--- a/src/element.rs
+++ b/src/element.rs
@@ -105,7 +105,6 @@ pub struct ElementInner<T: SetAttributes + Draw> {
transform: Transform,
values: ComputedValues,
cond: bool,
- style_attr: String,
pub element_impl: T,
}
@@ -129,12 +128,9 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
transform: Default::default(),
values: Default::default(),
cond: true,
- style_attr: String::new(),
element_impl,
};
- e.save_style_attribute();
-
let mut set_attributes = || -> Result<(), ElementError> {
e.set_transform_attribute()?;
e.set_conditional_processing_attributes()?;
@@ -185,16 +181,6 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
self.transform
}
- fn save_style_attribute(&mut self) {
- self.style_attr.push_str(
- self.attributes
- .iter()
- .find(|(attr, _)| attr.expanded() == expanded_name!("", "style"))
- .map(|(_, value)| value)
- .unwrap_or(""),
- );
- }
-
fn set_transform_attribute(&mut self) -> Result<(), ElementError> {
self.transform = self
.attributes
@@ -272,9 +258,14 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
);
}
- /// Applies CSS styles from the saved value of the "style" attribute
+ /// Applies CSS styles from the "style" attribute
fn set_style_attribute(&mut self) {
- let style = &self.style_attr;
+ let style = self
+ .attributes
+ .iter()
+ .find(|(attr, _)| attr.expanded() == expanded_name!("", "style"))
+ .map(|(_, value)| value)
+ .unwrap_or("");
if !style.is_empty() {
if let Err(e) = self.specified_values.parse_style_declarations(
@@ -285,9 +276,6 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
self.set_error(e);
}
}
-
- self.style_attr.clear();
- self.style_attr.shrink_to_fit();
}
fn set_error(&mut self, error: ElementError) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]