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 983ed09  Fix some typos and eliminate string copy in `List` (#775)
983ed09 is described below

commit 983ed09f8ca75abcddd2d8289732b8e8053eded8
Author: mwish <[email protected]>
AuthorDate: Sun Aug 14 16:12:53 2022 +0800

    Fix some typos and eliminate string copy in `List` (#775)
---
 src/cluster.cc         |  4 ++--
 src/redis_bitmap.cc    |  2 +-
 src/redis_cmd.cc       | 11 ++++++++---
 src/redis_cmd.h        |  2 +-
 src/redis_list.cc      |  6 ++++--
 src/redis_sortedint.cc |  2 +-
 6 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/src/cluster.cc b/src/cluster.cc
index 0d5c454..c837806 100644
--- a/src/cluster.cc
+++ b/src/cluster.cc
@@ -40,11 +40,11 @@ Cluster::Cluster(Server *svr, std::vector<std::string> 
binds, int port) :
   }
 }
 
-// We access cluster without lock, acutally we guarantte data-safe by work 
theads
+// We access cluster without lock, actually we guarantee data-safe by work 
threads
 // ReadWriteLockGuard, CLUSTER command doesn't have 'execlusive' attribute, 
i.e.
 // CLUSTER command can be executed concurrently, but some subcommand may change
 // cluster data, so these commands should be executed exclusively, and 
ReadWriteLock
-// also can guarantte accessing data is safe.
+// also can guarantee accessing data is safe.
 bool Cluster::SubCommandIsExecExclusive(const std::string &subcommand) {
   if (strcasecmp("setnodes", subcommand.c_str()) == 0) {
     return true;
diff --git a/src/redis_bitmap.cc b/src/redis_bitmap.cc
index 91b24b2..eb0907c 100644
--- a/src/redis_bitmap.cc
+++ b/src/redis_bitmap.cc
@@ -144,7 +144,7 @@ rocksdb::Status Bitmap::GetString(const Slice &user_key, 
const uint32_t max_btos
                           static_cast<size_t>(kBitmapSegmentBytes),
                           static_cast<size_t>(metadata.size - frag_index)});
 
-    //  If you setbit bit 0 1, the value is stored as 0x01 in Kvocks but 0x80 
in Redis.
+    //  If you setbit bit 0 1, the value is stored as 0x01 in Kvrocks but 0x80 
in Redis.
     // So we need to swap bits is to keep the same return value as Redis.
     for (uint32_t i = 0; i < valid_size; i++) {
         if (!fragment[i]) continue;
diff --git a/src/redis_cmd.cc b/src/redis_cmd.cc
index aa8f84e..0e0ae25 100644
--- a/src/redis_cmd.cc
+++ b/src/redis_cmd.cc
@@ -1602,17 +1602,22 @@ class CommandBPop : public Commander {
 
   rocksdb::Status TryPopFromList() {
     Redis::List list_db(svr_->storage_, conn_->GetNamespace());
-    std::string last_key, elem;
+    std::string elem;
+    const std::string* last_key_ptr = nullptr;
     rocksdb::Status s;
     for (const auto &key : keys_) {
-      last_key = key;
+      last_key_ptr = &key;
       s = list_db.Pop(key, left_, &elem);
       if (s.ok() || !s.IsNotFound()) {
         break;
       }
     }
     if (s.ok()) {
-      conn_->Reply(Redis::MultiBulkString({last_key, elem}));
+      if (last_key_ptr == nullptr) {
+        conn_->Reply(Redis::MultiBulkString({"", std::move(elem)}));
+      } else {
+        conn_->Reply(Redis::MultiBulkString({*last_key_ptr, std::move(elem)}));
+      }
     } else if (!s.IsNotFound()) {
       conn_->Reply(Redis::Error("ERR " + s.ToString()));
       LOG(ERROR) << "Failed to execute redis command: " << 
conn_->current_cmd_->GetAttributes()->name
diff --git a/src/redis_cmd.h b/src/redis_cmd.h
index 32492cb..8b54df2 100644
--- a/src/redis_cmd.h
+++ b/src/redis_cmd.h
@@ -75,7 +75,7 @@ class Commander {
 
  protected:
   std::vector<std::string> args_;
-  const CommandAttributes *attributes_;
+  const CommandAttributes *attributes_ = nullptr;
 };
 
 using CommanderFactory = std::function<std::unique_ptr<Commander>()>;
diff --git a/src/redis_list.cc b/src/redis_list.cc
index fe851fe..16fe779 100644
--- a/src/redis_list.cc
+++ b/src/redis_list.cc
@@ -20,7 +20,9 @@
 
 #include "redis_list.h"
 
-#include <stdlib.h>
+#include <cstdlib>
+#include <utility>
+
 #include "db_util.h"
 
 namespace Redis {
@@ -96,7 +98,7 @@ rocksdb::Status List::Pop(const Slice &user_key, bool left, 
std::string *elem) {
   auto s = PopMulti(user_key, left, 1, &elems);
   if (!s.ok()) return s;
 
-  *elem = elems[0];
+  *elem = std::move(elems[0]);
   return rocksdb::Status::OK();
 }
 
diff --git a/src/redis_sortedint.cc b/src/redis_sortedint.cc
index 638afcd..e1b3703 100644
--- a/src/redis_sortedint.cc
+++ b/src/redis_sortedint.cc
@@ -154,7 +154,7 @@ rocksdb::Status Sortedint::Range(const Slice &user_key,
     GetFixed64(&sub_key, &id);
     if ( id == cursor_id || pos++ < offset ) continue;
     ids->emplace_back(id);
-    if (limit > 0 && ids && ids->size() >= limit) break;
+    if (limit > 0 && ids->size() >= limit) break;
   }
   return rocksdb::Status::OK();
 }

Reply via email to