Commit 14e545b6 authored by Joe Tsai's avatar Joe Tsai Committed by Joe Tsai

archive/tar: reduce allocations in formatOctal

Change-Id: I9ddb7d2a97d28aba7a107b65f278993daf7807fa
Reviewed-on: https://go-review.googlesource.com/30960Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 6da8bdd2
...@@ -156,12 +156,11 @@ func (p *parser) parseOctal(b []byte) int64 { ...@@ -156,12 +156,11 @@ func (p *parser) parseOctal(b []byte) int64 {
return int64(x) return int64(x)
} }
// Encode x as an octal ASCII string and write it into b with leading zeros.
func (f *formatter) formatOctal(b []byte, x int64) { func (f *formatter) formatOctal(b []byte, x int64) {
s := strconv.FormatInt(x, 8) s := strconv.FormatInt(x, 8)
// leading zeros, but leave room for a NUL. // Add leading zeros, but leave room for a NUL.
for len(s)+1 < len(b) { if n := len(b) - len(s) - 1; n > 0 {
s = "0" + s s = strings.Repeat("0", n) + s
} }
f.formatString(b, s) f.formatString(b, s)
} }
......
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