Fix silly loop
authorunc0rr
Tue, 23 Oct 2018 21:36:51 +0200
changeset 13972 03e41712eef8
parent 13971 48796bef9e69
child 13973 d12ca66054aa
Fix silly loop
rust/land2d/src/lib.rs
--- a/rust/land2d/src/lib.rs	Sat Oct 20 13:22:30 2018 +0200
+++ b/rust/land2d/src/lib.rs	Tue Oct 23 21:36:51 2018 +0200
@@ -121,53 +121,45 @@
             1,
         );
 
-        loop {
-            let a = stack.pop();
-            match a {
-                None => return,
-                Some(a) => {
-                    let (mut xl, mut xr, y, mut dir) = a;
+        while let Some(a) = stack.pop() {
+            let (mut xl, mut xr, y, mut dir) = a;
 
-                    while xl > 0 && self
-                        .pixels
-                        .get(y, xl)
-                        .map_or(false, |v| *v != border_value && *v != fill_value)
-                    {
-                        xl -= 1;
-                    }
+            while xl > 0 && self
+                .pixels
+                .get(y, xl)
+                .map_or(false, |v| *v != border_value && *v != fill_value)
+            {
+                xl -= 1;
+            }
 
-                    while xr < self.width() - 1 && self
-                        .pixels
-                        .get(y, xr)
-                        .map_or(false, |v| *v != border_value && *v != fill_value)
-                    {
-                        xr += 1;
-                    }
+            while xr < self.width() - 1 && self
+                .pixels
+                .get(y, xr)
+                .map_or(false, |v| *v != border_value && *v != fill_value)
+            {
+                xr += 1;
+            }
 
-                    while xl < xr {
-                        while xl <= xr
-                            && (self.pixels[y][xl] == border_value
-                                || self.pixels[y][xl] == fill_value)
-                        {
-                            xl += 1;
-                        }
+            while xl < xr {
+                while xl <= xr
+                    && (self.pixels[y][xl] == border_value || self.pixels[y][xl] == fill_value)
+                {
+                    xl += 1;
+                }
 
-                        let mut x = xl;
+                let mut x = xl;
 
-                        while xl <= xr
-                            && (self.pixels[y][xl] != border_value
-                                && self.pixels[y][xl] != fill_value)
-                        {
-                            self.pixels[y][xl] = fill_value;
+                while xl <= xr
+                    && (self.pixels[y][xl] != border_value && self.pixels[y][xl] != fill_value)
+                {
+                    self.pixels[y][xl] = fill_value;
 
-                            xl += 1;
-                        }
+                    xl += 1;
+                }
 
-                        if x < xl {
-                            push(self, &mut stack, x, xl - 1, y, dir);
-                            push(self, &mut stack, x, xl - 1, y, -dir);
-                        }
-                    }
+                if x < xl {
+                    push(self, &mut stack, x, xl - 1, y, dir);
+                    push(self, &mut stack, x, xl - 1, y, -dir);
                 }
             }
         }