From: Sage Weil Date: Fri, 15 May 2020 19:59:01 +0000 (-0500) Subject: common/FastCDC: refactor scan into a helper X-Git-Tag: v16.1.0~2230^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=39cbc6443ec0286c94be789d2f31ffc1bd78b806;p=ceph.git common/FastCDC: refactor scan into a helper Signed-off-by: Sage Weil --- diff --git a/src/common/FastCDC.cc b/src/common/FastCDC.cc index 5fa8e0d98531..0836aa6468b6 100644 --- a/src/common/FastCDC.cc +++ b/src/common/FastCDC.cc @@ -57,6 +57,22 @@ void FastCDC::_setup(int target, int size_window_bits) } } +static inline bool _scan( + unsigned char *ptr, size_t& pos, size_t max, uint64_t mask, uint64_t& fp, + uint64_t *table) +{ + while (true) { + if ((fp & mask) == mask) { + return false; + } + if (pos >= max) { + return true; + } + fp = (fp << 1) ^ table[ptr[pos]]; + ++pos; + } +} + void FastCDC::calc_chunks( bufferlist& bl, std::vector> *chunks) @@ -85,29 +101,18 @@ void FastCDC::calc_chunks( } // find an end marker - // small - size_t max = std::min(len, - cstart + (1 << (target_bits - TARGET_WINDOW_BITS))); - while ((fp & small_mask) != small_mask && pos < max) { - fp = (fp << 1) ^ table[ptr[pos]]; - ++pos; - } - if (pos >= max) { - // target - max = std::min(len, cstart + (1 << (target_bits + TARGET_WINDOW_BITS))); - while ((fp & target_mask) != target_mask && pos < max) { - fp = (fp << 1) ^ table[ptr[pos]]; - ++pos; - } - if (pos >= max) { - // large - max = std::min(len, cstart + (1 << max_bits)); - while ((fp & large_mask) != large_mask && pos < max) { - fp = (fp << 1) ^ table[ptr[pos]]; - ++pos; - } - } - } + if (_scan(ptr, pos, + std::min(len, + cstart + (1 << (target_bits - TARGET_WINDOW_BITS))), + small_mask, fp, table) && + _scan(ptr, pos, + std::min(len, + cstart + (1 << (target_bits + TARGET_WINDOW_BITS))), + target_mask, fp, table) && + _scan(ptr, pos, + std::min(len, + cstart + (1 << max_bits)), + large_mask, fp, table)) ; chunks->push_back(std::pair(cstart, pos - cstart)); }