From: Steinar H. Gunderson Date: Sun, 14 Dec 2014 19:22:33 +0000 (+0100) Subject: Small cleanup. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=4e78c9e91ab923c172833b7828b733b2bf89569c;p=remoteglot-book Small cleanup. --- diff --git a/binloader.cpp b/binloader.cpp index 2ed60cb..ab3e8ae 100644 --- a/binloader.cpp +++ b/binloader.cpp @@ -19,7 +19,22 @@ 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; } };