Skip to content

Commit

Permalink
Use Fprintf in commandBytes
Browse files Browse the repository at this point in the history
This avoids an extra copy in WriteString
  • Loading branch information
hoisie committed Jun 26, 2013
1 parent f1b3e0c commit 8b62c90
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ func writeRequest(writer io.Writer, cmd string, args ...string) error {
}

func commandBytes(cmd string, args ...string) []byte {
cmdbuf := bytes.NewBufferString(fmt.Sprintf("*%d\r\n$%d\r\n%s\r\n", len(args)+1, len(cmd), cmd))
var cmdbuf bytes.Buffer
fmt.Fprintf(&cmdbuf, "*%d\r\n$%d\r\n%s\r\n", len(args)+1, len(cmd), cmd)
for _, s := range args {
cmdbuf.WriteString(fmt.Sprintf("$%d\r\n%s\r\n", len(s), s))
fmt.Fprintf(&cmdbuf, "$%d\r\n%s\r\n", len(s), s)
}
return cmdbuf.Bytes()
}
Expand Down

0 comments on commit 8b62c90

Please sign in to comment.