[librsvg: 41/45] ElementInner: remove the big result field, and substitute for a small bool




commit b0559cba3a3598a2db10617e6f93ad57c73b6337
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Aug 23 20:13:11 2022 -0500

    ElementInner: remove the big result field, and substitute for a small bool
    
    Now we log a message with the error that set the element to be in an
    error state.  This makes the ElementInner structure a good bit smaller
    - it shrinks from 1008 bytes to 952 bytes.
    
    Fixes #706 - the last part of it.
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/731>

 src/element.rs | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
---
diff --git a/src/element.rs b/src/element.rs
index c944336cf..96cc2302f 100644
--- a/src/element.rs
+++ b/src/element.rs
@@ -98,7 +98,7 @@ pub struct ElementInner<T: SetAttributes + Draw> {
     attributes: Attributes,
     specified_values: SpecifiedValues,
     important_styles: HashSet<QualName>,
-    result: ElementResult,
+    is_in_error: bool,
     values: ComputedValues,
     required_extensions: Option<RequiredExtensions>,
     required_features: Option<RequiredFeatures>,
@@ -111,7 +111,7 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
         session: &Session,
         element_name: QualName,
         attributes: Attributes,
-        result: Result<(), ElementError>,
+        is_in_error: bool,
         element_impl: T,
     ) -> ElementInner<T> {
         let mut e = Self {
@@ -119,7 +119,7 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
             attributes,
             specified_values: Default::default(),
             important_styles: Default::default(),
-            result,
+            is_in_error,
             values: Default::default(),
             required_extensions: Default::default(),
             required_features: Default::default(),
@@ -253,11 +253,11 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
 
     fn set_error(&mut self, error: ElementError, session: &Session) {
         rsvg_log_session!(session, "setting node {} in error: {}", self, error);
-        self.result = Err(error);
+        self.is_in_error = true;
     }
 
     fn is_in_error(&self) -> bool {
-        self.result.is_err()
+        self.is_in_error
     }
 }
 
@@ -599,13 +599,20 @@ macro_rules! e {
         ) -> Element {
             let mut element_impl = <$element_type>::default();
 
-            let result = element_impl.set_attributes(&attributes, session);
+            let is_in_error = if let Err(e) = element_impl.set_attributes(&attributes, session) {
+                // FIXME: this does not provide a clue of what was the problematic attribute, or the
+                // problematic element.  We need tracking of the current parsing position to do that.
+                rsvg_log_session!(session, "setting element in error: {}", e);
+                true
+            } else {
+                false
+            };
 
             let element = Element::$element_type(Box::new(ElementInner::new(
                 session,
                 element_name.clone(),
                 attributes,
-                result,
+                is_in_error,
                 element_impl,
             )));
 


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