diff --git a/src/cluster/redis_slot.cc b/src/cluster/redis_slot.cc index 627877895ed..3843eb0faf1 100644 --- a/src/cluster/redis_slot.cc +++ b/src/cluster/redis_slot.cc @@ -47,10 +47,9 @@ static const uint16_t crc16tab[256] = { 0x1ce0, 0x0cc1, 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0}; -uint16_t Crc16(const char *buf, int len) { - int i = 0; +uint16_t Crc16(const char *buf, size_t len) { uint16_t crc = 0; - for (i = 0; i < len; i++) crc = (crc << 8) ^ crc16tab[((crc >> 8) ^ *buf++) & 0x00FF]; + for (size_t i = 0; i < len; i++) crc = (crc << 8) ^ crc16tab[((crc >> 8) ^ *buf++) & 0x00FF]; return crc; } @@ -60,8 +59,8 @@ uint16_t GetSlotIdFromKey(const std::string &key) { tag = key; } - auto crc = Crc16(tag.data(), static_cast(tag.size())); - return static_cast(crc & HASH_SLOTS_MASK); + auto crc = Crc16(tag.data(), tag.size()); + return crc & HASH_SLOTS_MASK; } std::string GetTagFromKey(const std::string &key) { diff --git a/src/cluster/redis_slot.h b/src/cluster/redis_slot.h index 5e55d124a4b..63c98d2e37e 100644 --- a/src/cluster/redis_slot.h +++ b/src/cluster/redis_slot.h @@ -26,6 +26,6 @@ constexpr const uint16_t HASH_SLOTS_MASK = 0x3fff; constexpr const uint16_t HASH_SLOTS_SIZE = HASH_SLOTS_MASK + 1; // 16384 constexpr const uint16_t HASH_SLOTS_MAX_ITERATIONS = 50; -uint16_t Crc16(const char *buf, int len); +uint16_t Crc16(const char *buf, size_t len); uint16_t GetSlotIdFromKey(const std::string &key); std::string GetTagFromKey(const std::string &key);