[gnome-klotski] Use uint8 a bit more.



commit 7d2b865fd7d55ef7157b2019bd2c0f05dbe7e76e
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun Feb 9 05:43:19 2020 +0100

    Use uint8 a bit more.

 src/puzzle.vala | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
---
diff --git a/src/puzzle.vala b/src/puzzle.vala
index 82694b2..739ad96 100644
--- a/src/puzzle.vala
+++ b/src/puzzle.vala
@@ -26,7 +26,7 @@ private class Puzzle : Object
 
         32 64 128
     */
-    private const int [] image_map =
+    private const uint8 [] image_map =
     {
         0,    0, // 🞍
 
@@ -122,12 +122,10 @@ private class Puzzle : Object
         116, 18, // top-right and bottom-left
 
         /* top and left and right */
-        26,  25, // used in Shark and Transeuropa (2/2)
+        26,  25  // used in Shark and Transeuropa (2/2)
         // many more of this kind doable
-
-        /* end of array */
-        -1,  -1
     };
+    private uint8 image_map_length = 54;
 
     [CCode (notify = false)] public uint8   width       { internal get; protected construct; }
     [CCode (notify = false)] public uint8   height      { internal get; protected construct; }
@@ -209,11 +207,12 @@ private class Puzzle : Object
         if (map [((uint16) x + 1) + ((uint16) y + 1) * ((uint16) width + 2)] == c)
             nr += 128;
 
-        uint8 i = 0;
-        while (nr != image_map [i] && image_map [i] != -1)
-            i += 2;
-
-        return image_map [i + 1];
+        for (uint8 i = 0; i < image_map_length * 2; i += 2)
+        {
+            if (nr == image_map [i])
+                return image_map [i + 1];
+        }
+        assert_not_reached ();
     }
 
     internal bool game_over ()


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