diff options
| author | Joe Tsai <joetsai@digital-static.net> | 2016-10-12 11:36:18 -0700 |
|---|---|---|
| committer | Joe Tsai <thebrokentoaster@gmail.com> | 2016-10-12 21:27:51 +0000 |
| commit | 14e545b60a8c78aa6609d807b4f50e54e9bfe1eb (patch) | |
| tree | f786670a9f3561139ba7330f9fef2cb3de220e43 /src | |
| parent | 6da8bdd2cc7a10f037a2025ffed57627d97a990c (diff) | |
| download | go-14e545b60a8c78aa6609d807b4f50e54e9bfe1eb.tar.xz | |
archive/tar: reduce allocations in formatOctal
Change-Id: I9ddb7d2a97d28aba7a107b65f278993daf7807fa
Reviewed-on: https://go-review.googlesource.com/30960
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/archive/tar/strconv.go | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/archive/tar/strconv.go b/src/archive/tar/strconv.go index 2619bcdde4..45e46b13b8 100644 --- a/src/archive/tar/strconv.go +++ b/src/archive/tar/strconv.go @@ -156,12 +156,11 @@ func (p *parser) parseOctal(b []byte) int64 { 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) { s := strconv.FormatInt(x, 8) - // leading zeros, but leave room for a NUL. - for len(s)+1 < len(b) { - s = "0" + s + // Add leading zeros, but leave room for a NUL. + if n := len(b) - len(s) - 1; n > 0 { + s = strings.Repeat("0", n) + s } f.formatString(b, s) } |
