mapleFU commented on code in PR #2627:
URL: https://github.com/apache/kvrocks/pull/2627#discussion_r1820403798


##########
src/server/redis_reply.cc:
##########
@@ -37,9 +37,23 @@ namespace redis {
 
 void Reply(evbuffer *output, const std::string &data) { evbuffer_add(output, 
data.c_str(), data.length()); }
 
-std::string SimpleString(const std::string &data) { return "+" + data + CRLF; }
+std::string SimpleString(std::string_view data) {
+  std::string res;
+  res.reserve(data.size() + 3);  // 1 for '+', 2 for CRLF
+  res += RESP_PREFIX_SIMPLE_STRING;
+  res += data;
+  res += CRLF;
+  return res;
+}
 
-std::string Error(const Status &s) { return RESP_PREFIX_ERROR + 
StatusToRedisErrorMsg(s) + CRLF; }
+std::string Error(const Status &s) {
+  std::string res;
+  res.reserve(s.Msg().size() + 3);  // 1 for '-', 2 for CRLF

Review Comment:
   > However, performing a hash lookup here to confirm the reserved length 
might be a bit heavy.
   
   As the hash table is small and anyway it would be built 😅, I think construct 
error string firstly is ok...
   
   > do you think it’s a good idea to directly use std::max(16, s.Msg().size() 
+ 3)
   
   It would be good if it's a critical path, but I don't think the error path 
worth this, since the current code is clear to understand and Error path might 
not a bottleneck...



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to