[librsvg: 1/3] gradient.rs: Refactor a for-loop to iterator combinators chain.



commit 909d9b7844a745c504336eb0a1fcb6a8a4688703
Author: Jordan Petridis <jordanpetridis protonmail com>
Date:   Fri Mar 16 03:08:16 2018 +0200

    gradient.rs: Refactor a for-loop to iterator combinators chain.

 rsvg_internals/src/gradient.rs | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
---
diff --git a/rsvg_internals/src/gradient.rs b/rsvg_internals/src/gradient.rs
index b394e0e3..fb7b4981 100644
--- a/rsvg_internals/src/gradient.rs
+++ b/rsvg_internals/src/gradient.rs
@@ -308,19 +308,17 @@ impl Gradient {
                 || node.get_type() == NodeType::RadialGradient
         );
 
-        for child in node.children() {
-            if child.get_type() != NodeType::Stop {
-                continue; // just ignore this child; we are only interested in gradient stops
-            }
-
-            if child.get_result().is_err() {
-                break; // don't add any more stops
-            }
-
-            child.with_impl(|stop: &NodeStop| {
-                self.add_color_stop(stop.get_offset(), stop.get_rgba());
+        node.children()
+             .into_iter()
+             // just ignore this child; we are only interested in gradient stops
+             .filter(|child| child.get_type() == NodeType::Stop)
+             // don't add any more stops, Eq to break in for-loop
+             .take_while(|child| child.get_result().is_ok())
+             .for_each(|child| {
+                child.with_impl(|stop: &NodeStop| {
+                    self.add_color_stop(stop.get_offset(), stop.get_rgba());
+                })
             });
-        }
     }
 
     fn add_color_stop(&mut self, offset: f64, rgba: u32) {


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