pkg/escape: Preallocate output in Unescape

Preallocating the capacity of the output is faster and uses less
memory than letting append() do its own (over)allocation.
pull/9101/head
Menno Finlay-Smits 2017-11-14 11:50:00 +13:00
parent 1b2301cc15
commit b0e871876a
1 changed files with 5 additions and 1 deletions

View File

@ -78,7 +78,11 @@ func Unescape(in []byte) []byte {
i := 0
inLen := len(in)
var out []byte
// The output size will be no more than inLen. Preallocating the
// capacity of the output is faster and uses less memory than
// letting append() do its own (over)allocation.
out := make([]byte, 0, inLen)
for {
if i >= inLen {