Unverified Commit afd9e3ed authored by judeng's avatar judeng Committed by GitHub
Browse files

Optimize the performance of sdscatrepr in printable characters (#11725)

sdscatrepr is not the hot path in redis, but it's still useful to have make it less wasteful.
parent c95ff0f3
...@@ -997,6 +997,7 @@ void sdsfreesplitres(sds *tokens, int count) { ...@@ -997,6 +997,7 @@ void sdsfreesplitres(sds *tokens, int count) {
* After the call, the modified sds string is no longer valid and all the * After the call, the modified sds string is no longer valid and all the
* references must be substituted with the new pointer returned by the call. */ * references must be substituted with the new pointer returned by the call. */
sds sdscatrepr(sds s, const char *p, size_t len) { sds sdscatrepr(sds s, const char *p, size_t len) {
s = sdsMakeRoomFor(s, len + 2);
s = sdscatlen(s,"\"",1); s = sdscatlen(s,"\"",1);
while(len--) { while(len--) {
switch(*p) { switch(*p) {
...@@ -1011,7 +1012,7 @@ sds sdscatrepr(sds s, const char *p, size_t len) { ...@@ -1011,7 +1012,7 @@ sds sdscatrepr(sds s, const char *p, size_t len) {
case '\b': s = sdscatlen(s,"\\b",2); break; case '\b': s = sdscatlen(s,"\\b",2); break;
default: default:
if (isprint(*p)) if (isprint(*p))
s = sdscatprintf(s,"%c",*p); s = sdscatlen(s, p, 1);
else else
s = sdscatprintf(s,"\\x%02x",(unsigned char)*p); s = sdscatprintf(s,"\\x%02x",(unsigned char)*p);
break; break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment