diff options
author | Keith Bostic <keith@wiredtiger.com> | 2015-05-03 14:06:58 -0400 |
---|---|---|
committer | Keith Bostic <keith@wiredtiger.com> | 2015-05-03 14:06:58 -0400 |
commit | a560965c419344b3d68084914ff3ba29ae1585be (patch) | |
tree | 4f9fdbfefc57f897ea529b04726bbbbd3fa87d3a /ext | |
parent | a6b97ac069f4e1755c96910880f49405c47e40d1 (diff) | |
download | mongo-a560965c419344b3d68084914ff3ba29ae1585be.tar.gz |
Rewrite the binary search function (I took zlib's, but zlib's search
is fundamentally different, LZ4's search has different needs.)
Diffstat (limited to 'ext')
-rw-r--r-- | ext/compressors/lz4/lz4_compress.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/ext/compressors/lz4/lz4_compress.c b/ext/compressors/lz4/lz4_compress.c index 7cdd1602128..f05e40ae691 100644 --- a/ext/compressors/lz4/lz4_compress.c +++ b/ext/compressors/lz4/lz4_compress.c @@ -168,20 +168,25 @@ lz4_find_slot(int target_arg, uint32_t *offsets, uint32_t slots) { uint32_t base, indx, limit, target; - indx = 1; + indx = 1; /* -Wuninitialized */ + target = (uint32_t)target_arg; /* Type conversion */ - /* Figure out which slot we got to: binary search */ + /* Fast check if we consumed it all, it's a likely result. */ if (target >= offsets[slots]) - indx = slots; - else if (target > offsets[1]) - for (base = 2, limit = slots - base; limit != 0; limit >>= 1) { - indx = base + (limit >> 1); - if (target < offsets[indx]) - continue; + return (slots); + + /* + * Figure out which slot we got to: binary search. Note the test of + * offset (slot + 1), that's (end-byte + 1) for slot. + */ + for (base = 0, limit = slots; limit != 0; limit >>= 1) { + indx = base + (limit >> 1); + if (target > offsets[indx + 1]) { base = indx + 1; --limit; } + } return (indx); } |