Commit 9f6b430b authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Simplify prefix_cmp.

parent 6d99bd57
...@@ -494,25 +494,22 @@ enum prefix_status ...@@ -494,25 +494,22 @@ enum prefix_status
prefix_cmp(const unsigned char *p1, unsigned char plen1, prefix_cmp(const unsigned char *p1, unsigned char plen1,
const unsigned char *p2, unsigned char plen2) const unsigned char *p2, unsigned char plen2)
{ {
int min = MIN(plen1, plen2); int plen = MIN(plen1, plen2);
unsigned char mask = 0xFF;
int i = 0;
while(i < min / 8) { if(memcmp(p1, p2, plen / 8) != 0)
if(p1[i] != p2[i]) return PST_DISJOINT;
return PST_DISJOINT;
i++; if(plen % 8 != 0) {
} int i = plen / 8 + 1;
min -= i * 8; unsigned char mask = (0xFF << (plen % 8)) & 0xFF;
if(min != 0) {
mask <<= 8 - min;
if((p1[i] & mask) != (p2[i] & mask)) if((p1[i] & mask) != (p2[i] & mask))
return PST_DISJOINT; return PST_DISJOINT;
} }
if(plen1 < plen2) if(plen1 < plen2)
return PST_LESS_SPECIFIC; return PST_LESS_SPECIFIC;
if(plen1 > plen2) else if(plen1 > plen2)
return PST_MORE_SPECIFIC; return PST_MORE_SPECIFIC;
return PST_EQUALS; else
return PST_EQUALS;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment