This is an automated email from the ASF dual-hosted git repository.

twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/incubator-kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new 30e9fd78 Remove useless type cast in redis_slot.cc (#1409)
30e9fd78 is described below

commit 30e9fd788a4acb585566a008f4d5fff65ee06ce3
Author: Twice <[email protected]>
AuthorDate: Sat Apr 29 20:43:21 2023 +0800

    Remove useless type cast in redis_slot.cc (#1409)
---
 src/cluster/redis_slot.cc | 9 ++++-----
 src/cluster/redis_slot.h  | 2 +-
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/cluster/redis_slot.cc b/src/cluster/redis_slot.cc
index 62787789..3843eb0f 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<int>(tag.size()));
-  return static_cast<int>(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 5e55d124..63c98d2e 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);

Reply via email to