[librsvg/librsvg-2.50] Remove the style_attr String from ElementInner; fetch it from the Attributes



commit 00a371bde968a610510a7b49d4d800458792b1d2
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.

 rsvg_internals/src/element.rs | 26 +++++++-------------------
 1 file changed, 7 insertions(+), 19 deletions(-)
---
diff --git a/rsvg_internals/src/element.rs b/rsvg_internals/src/element.rs
index 583aaef1..e06a3527 100644
--- a/rsvg_internals/src/element.rs
+++ b/rsvg_internals/src/element.rs
@@ -106,7 +106,6 @@ pub struct ElementInner<T: SetAttributes + Draw> {
     transform: Transform,
     values: ComputedValues,
     cond: bool,
-    style_attr: String,
     pub element_impl: T,
 }
 
@@ -130,12 +129,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()?;
@@ -186,16 +182,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
@@ -273,9 +259,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(
@@ -286,9 +277,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]