Skip to content

Commit 82d1303

Browse files
committed
Avoid superfluous allocations in RespSerializer
1 parent 5723398 commit 82d1303

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

redisdump/redisdump.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,12 @@ func zsetToRedisCmd(k string, val []string) []string {
5555

5656
// RESPSerializer will serialize cmd to RESP
5757
func RESPSerializer(cmd []string) string {
58-
s := ""
59-
s += "*" + strconv.Itoa(len(cmd)) + "\r\n"
58+
buf := strings.Builder{}
59+
buf.WriteString("*" + strconv.Itoa(len(cmd)) + "\r\n")
6060
for _, arg := range cmd {
61-
s += "$" + strconv.Itoa(len(arg)) + "\r\n"
62-
s += arg + "\r\n"
61+
buf.WriteString("$" + strconv.Itoa(len(arg)) + "\r\n" + arg + "\r\n")
6362
}
64-
return s
63+
return buf.String()
6564
}
6665

6766
// RedisCmdSerializer will serialize cmd to a string with redis commands

0 commit comments

Comments
 (0)