You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by GitBox <gi...@apache.org> on 2022/09/17 06:18:13 UTC

[GitHub] [incubator-kvrocks] PragmaTwice commented on a diff in pull request #881: [WIP] Implement the command `hello`

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


##########
src/redis_reply.cc:
##########
@@ -45,36 +45,43 @@ std::string MultiLen(int64_t len) {
   return "*"+std::to_string(len)+"\r\n";
 }
 
-std::string MultiBulkString(std::vector<std::string> values, bool output_nil_for_empty_string) {
+std::string MultiBulkString(const std::vector<std::string>& values, bool output_nil_for_empty_string) {
+  std::vector<std::string> copiedStrings;
+  copiedStrings.resize(values.size());
   for (size_t i = 0; i < values.size(); i++) {
     if (values[i].empty() && output_nil_for_empty_string) {
-      values[i] = NilString();
+      copiedStrings[i] = NilString();
     }  else {
-      values[i] = BulkString(values[i]);
+      copiedStrings[i] = BulkString(values[i]);
     }
   }
-  return Array(values);
+  return Array(copiedStrings);
 }
 
 
-std::string MultiBulkString(std::vector<std::string> values, const std::vector<rocksdb::Status> &statuses) {
+std::string MultiBulkString(const std::vector<std::string>& values, const std::vector<rocksdb::Status> &statuses) {
+  std::vector<std::string> copiedStrings;
+  copiedStrings.resize(values.size());
   for (size_t i = 0; i < values.size(); i++) {
     if (i < statuses.size() && !statuses[i].ok()) {
-      values[i] = NilString();
+      copiedStrings[i] = NilString();
     } else {
-      values[i] = BulkString(values[i]);
+      copiedStrings[i] = BulkString(values[i]);
     }
   }
-  return Array(values);
+  return Array(copiedStrings);
 }
-std::string Array(std::vector<std::string> list) {
+
+std::string Array(const std::vector<std::string>& list) {
   std::string::size_type n = std::accumulate(
     list.begin(), list.end(), std::string::size_type(0),
     [] ( std::string::size_type n, const std::string &s ) { return ( n += s.size() ); });

Review Comment:
   ```suggestion
     size_t n = std::accumulate(
       list.begin(), list.end(), 0, [] (size_t n, const std::string &s) { return n + s.size(); });
   ```



-- 
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