Commit 8242d2e0 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Unroll keycompare

git-svn-id: file:///svn/tokudb@133 c7de825b-a66e-492c-adef-691d508d4ae1
parent 12c0bfee
......@@ -46,12 +46,36 @@ int keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2len) {
else return -1;
}
}
#elif 0
/* This one looks tighter, but it does use memcmp... */
int keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2len) {
int comparelen = key1len<key2len ? key1len : key2len;
const unsigned char *k1;
const unsigned char *k2;
for (k1=key1, k2=key2;
comparelen>0;
k1++, k2++, comparelen--) {
if (*k1 != *k2) {
return (int)*k1-(int)*k2;
}
}
return key1len-key2len;
}
#else
/* unroll that one twice */
int keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2len) {
int comparelen = key1len<key2len ? key1len : key2len;
const unsigned char *k1;
const unsigned char *k2;
for (k1=key1, k2=key2;
comparelen>4;
k1+=4, k2+=4, comparelen-=4) {
{ int v1=k1[0], v2=k2[0]; if (v1!=v2) return v1-v2; }
{ int v1=k1[1], v2=k2[1]; if (v1!=v2) return v1-v2; }
{ int v1=k1[2], v2=k2[2]; if (v1!=v2) return v1-v2; }
{ int v1=k1[3], v2=k2[3]; if (v1!=v2) return v1-v2; }
}
for (;
comparelen>0;
k1++, k2++, comparelen--) {
if (*k1 != *k2) {
......@@ -60,6 +84,7 @@ int keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2len) {
}
return key1len-key2len;
}
#endif
void test_keycompare (void) {
......
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