[librsvg: 8/11] Simplify two functions that deal with attributes




commit f7aaa84ba6258075b20c2a8920a05be19f197351
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Sep 7 16:48:08 2020 -0500

    Simplify two functions that deal with attributes

 rsvg_internals/src/element.rs | 30 ++++++++++++------------------
 1 file changed, 12 insertions(+), 18 deletions(-)
---
diff --git a/rsvg_internals/src/element.rs b/rsvg_internals/src/element.rs
index c5165a0f..9f07d394 100644
--- a/rsvg_internals/src/element.rs
+++ b/rsvg_internals/src/element.rs
@@ -188,31 +188,25 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
     }
 
     fn save_style_attribute(&mut self) {
-        let attrs = self.attributes.borrow();
-
-        let result = attrs
-            .iter()
-            .find(|(attr, _)| attr.expanded() == expanded_name!("", "style"))
-            .map(|(_, value)| value);
-        if let Some(value) = result {
-            self.style_attr.push_str(value);
-        }
+        self.style_attr.push_str(
+            self.attributes
+                .borrow()
+                .iter()
+                .find(|(attr, _)| attr.expanded() == expanded_name!("", "style"))
+                .map(|(_, value)| value)
+                .unwrap_or("")
+        );
     }
 
     fn set_transform_attribute(&mut self) -> Result<(), ElementError> {
-        let pair = self.attributes
+        self.transform = self.attributes
             .borrow()
             .iter()
             .find(|(attr, _)| attr.expanded() == expanded_name!("", "transform"))
             .map(|(attr, value)| {
-                (attr.clone(), value.to_string())
-            });
-
-        if let Some((attr, value)) = pair {
-            Transform::parse_str(&value).attribute(attr).map(|affine| {
-                self.transform = affine;
-            })?;
-        }
+                Transform::parse_str(value).attribute(attr)
+            })
+            .unwrap_or_else(|| Ok(Transform::default()))?;
 
         Ok(())
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]