changeset 1901:55392a6feead

Micro-optimize mapMatchBlock(), gain ~9.5% performance.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 06 Nov 2017 09:12:51 +0200
parents ed98d2fe4bca
children 5458d75dad67
files mapsearch.c
diffstat 1 files changed, 11 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mapsearch.c	Mon Nov 06 06:12:37 2017 +0200
+++ b/mapsearch.c	Mon Nov 06 09:12:51 2017 +0200
@@ -775,15 +775,21 @@
 
 int mapMatchBlock(const MapBlock *map, const MapBlock *match, const int ox, const int oy)
 {
-    for (int y = 0; y < match->height; y++)
+    const unsigned char
+        *sp = map->data + (oy * map->scansize) + ox,
+        *dp = match->data;
+
+    int yc = match->height;
+    while (yc--)
     {
-        unsigned char *dp = match->data + (y * match->scansize);
-        unsigned char *sp = map->data + ((y + oy) * map->scansize) + ox;
-        for (int x = 0; x < match->width; x++)
+        for (int xc = 0; xc < match->width; xc++)
         {
-            if (dp[x] != 0 && dp[x] != sp[x])
+            if (dp[xc] != 0 && dp[xc] != sp[xc])
                 return -1;
         }
+
+        sp += map->scansize;
+        dp += match->scansize;
     }
 
     return 100;