]> git.sesse.net Git - remoteglot-book/commitdiff
Small cleanup.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 14 Dec 2014 19:22:33 +0000 (20:22 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 14 Dec 2014 19:23:30 +0000 (20:23 +0100)
binloader.cpp

index 2ed60cbe78250ff34eba9f7c358968f90c4ddb97..ab3e8aeb71646700bc941546d6df875ebf1dfb64 100644 (file)
 
 using namespace std;
 
-Arena arena;
+static int memcmp_different_len(const void *s1, size_t n1, const void *s2, size_t n2)
+{
+       int shared_len = min(n1, n2);
+       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;
+       }
+}
 
 enum Result { WHITE = 0, DRAW, BLACK };
 struct Element {
@@ -33,15 +48,8 @@ struct Element {
        long start_position;
 
        bool operator< (const Element& other) const {
-               int shared_len = min(bpfen_len, other.bpfen_len);
-               int s = memcmp(bpfen, other.bpfen, shared_len);
-               if (s < 0) {
-                       return true;
-               } else if (s > 0) {
-                       return false;
-               } else {
-                       return bpfen_len < other.bpfen_len;
-               }
+               int s = memcmp_different_len(bpfen, bpfen_len, other.bpfen, other.bpfen_len);
+               return s < 0;
        }
 };