]> git.sesse.net Git - remoteglot-book/commitdiff
Speed up binloader by ~10-15%.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 15 Dec 2014 00:59:53 +0000 (01:59 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 15 Dec 2014 00:59:53 +0000 (01:59 +0100)
binloader.cpp

index 115cba61f571298146cf66ad44c0d473f3dafb3c..3877ffcaf827aa87267ff4237cc45796e1490641 100644 (file)
 
 using namespace std;
 
 
 using namespace std;
 
-static int memcmp_different_len(const void *s1, size_t n1, const void *s2, size_t n2)
+static inline int memcmp_different_len(const void *s1, size_t n1, const void *s2, size_t n2)
 {
 {
-       int shared_len = min(n1, n2);
+       size_t shared_len = min(n1, n2);
+       if (shared_len >= 8) {
+               uint64_t a1 = *(const uint64_t *)s1;
+               uint64_t a2 = *(const uint64_t *)s2;
+               if (a1 != a2) {
+                       a1 = __builtin_bswap64(a1);
+                       a2 = __builtin_bswap64(a2);
+                       return (a1 < a2) ? -1 : 1;
+               }
+       }
+
        int s = memcmp(s1, s2, shared_len);
        if (s != 0) {
                return s;
        }
 
        int s = memcmp(s1, s2, shared_len);
        if (s != 0) {
                return s;
        }
 
-       if (n1 < n2) {
-               return -1;
-       } else if (n1 > n2) {
-               return 1;
-       } else {
-               return 0;
-       }
+       return n2 - n1;
 }
 
 enum Result { WHITE = 0, DRAW, BLACK };
 }
 
 enum Result { WHITE = 0, DRAW, BLACK };