[librsvg] NodePath: store a plain PathBuilder, not Option<PathBuilder>



commit 9fa24530df3a8eb22df73c218436f5263459724e
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Oct 23 20:03:28 2019 -0500

    NodePath: store a plain PathBuilder, not Option<PathBuilder>
    
    The core render_path_builder() already knows how to deal with empty
    paths; I think the Option is from before the time we had
    path_builder.is_empty().

 rsvg_internals/src/path_builder.rs |  9 +--------
 rsvg_internals/src/shapes.rs       | 15 +++------------
 2 files changed, 4 insertions(+), 20 deletions(-)
---
diff --git a/rsvg_internals/src/path_builder.rs b/rsvg_internals/src/path_builder.rs
index 62218195..8c733725 100644
--- a/rsvg_internals/src/path_builder.rs
+++ b/rsvg_internals/src/path_builder.rs
@@ -290,18 +290,11 @@ impl PathCommand {
     }
 }
 
+#[derive(Default)]
 pub struct PathBuilder {
     path_commands: Vec<PathCommand>,
 }
 
-impl Default for PathBuilder {
-    fn default() -> PathBuilder {
-        PathBuilder {
-            path_commands: Vec::new(),
-        }
-    }
-}
-
 impl PathBuilder {
     pub fn new() -> PathBuilder {
         PathBuilder::default()
diff --git a/rsvg_internals/src/shapes.rs b/rsvg_internals/src/shapes.rs
index 933383ca..a5eb5354 100644
--- a/rsvg_internals/src/shapes.rs
+++ b/rsvg_internals/src/shapes.rs
@@ -114,23 +114,19 @@ fn render_ellipse(
 
 #[derive(Default)]
 pub struct NodePath {
-    builder: Option<PathBuilder>,
+    builder: PathBuilder,
 }
 
 impl NodeTrait for NodePath {
     fn set_atts(&mut self, _: Option<&RsvgNode>, pbag: &PropertyBag<'_>) -> NodeResult {
         for (attr, value) in pbag.iter() {
             if attr == local_name!("d") {
-                let mut builder = PathBuilder::new();
-
-                if let Err(e) = path_parser::parse_path_into_builder(value, &mut builder) {
+                if let Err(e) = path_parser::parse_path_into_builder(value, &mut self.builder) {
                     // FIXME: we don't propagate errors upstream, but creating a partial
                     // path is OK per the spec
 
                     rsvg_log!("could not parse path: {}", e);
                 }
-
-                self.builder = Some(builder);
             }
         }
 
@@ -145,12 +141,7 @@ impl NodeTrait for NodePath {
         clipping: bool,
     ) -> Result<BoundingBox, RenderingError> {
         let values = cascaded.get();
-
-        if let Some(ref builder) = self.builder {
-            render_path_builder(builder, draw_ctx, node, values, true, clipping)
-        } else {
-            Ok(draw_ctx.empty_bbox())
-        }
+        render_path_builder(&self.builder, draw_ctx, node, values, true, clipping)
     }
 }
 


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