You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "PragmaTwice (via GitHub)" <gi...@apache.org> on 2023/05/20 08:31:00 UTC

[GitHub] [incubator-kvrocks] PragmaTwice commented on a diff in pull request #1444: feat: add sintercard command from redis 7.0

PragmaTwice commented on code in PR #1444:
URL: https://github.com/apache/incubator-kvrocks/pull/1444#discussion_r1199579994


##########
src/types/redis_set.cc:
##########
@@ -338,19 +338,43 @@ rocksdb::Status Set::Inter(const std::vector<Slice> &keys, std::vector<std::stri
   for (const auto &member : target_members) {
     member_counters[member] = 1;
   }
+
+  bool has_limit = limit != 0;
+  bool limited = false;
   for (size_t i = 1; i < keys.size(); i++) {
     s = Members(keys[i], &target_members);
     if (!s.ok() || target_members.empty()) return s;
     for (const auto &member : target_members) {
-      if (member_counters.find(member) == member_counters.end()) continue;
+      if (member_counters.count(member) == 0) continue;
       member_counters[member]++;
+      if (has_limit && member_counters[member] == keys.size()) {

Review Comment:
   Why do we search for the `member` element three times in `member_counters` continuously? It looks so bad to me.
   
   ```c++
   auto iter = find(member); // find it
   use1(iter); // use it
   use2(iter);
   
   // **NOT**:
   use1(find(member));
   use2(find(member));
   use3(find(member));
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org