Skip to content

Commit

Permalink
Remove useless type cast in redis_slot.cc (#1409)
Browse files Browse the repository at this point in the history
  • Loading branch information
PragmaTwice authored Apr 29, 2023
1 parent 628fc2d commit 30e9fd7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/cluster/redis_slot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/cluster/redis_slot.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 30e9fd7

Please sign in to comment.