mirror of
https://github.com/golang/go
synced 2024-11-23 23:10:09 -07:00
cmd/internal/obj: reuse the varint encoding buffer
This reduces the number of allocations in the compiler while building the stdlib by 15.66%. No functional changes. Passes toolstash -cmp. Change-Id: Ia21b37134a8906a4e23d53fdc15235b4aa7bbb34 Reviewed-on: https://go-review.googlesource.com/9085 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
3c939b5348
commit
873483c682
@ -463,18 +463,21 @@ func writesym(ctxt *Link, b *Biobuf, s *LSym) {
|
||||
}
|
||||
}
|
||||
|
||||
// Reusable buffer to avoid allocations.
|
||||
// This buffer was responsible for 15% of gc's allocations.
|
||||
var varintbuf [10]uint8
|
||||
|
||||
func wrint(b *Biobuf, sval int64) {
|
||||
var v uint64
|
||||
var buf [10]uint8
|
||||
uv := (uint64(sval) << 1) ^ uint64(int64(sval>>63))
|
||||
p := buf[:]
|
||||
p := varintbuf[:]
|
||||
for v = uv; v >= 0x80; v >>= 7 {
|
||||
p[0] = uint8(v | 0x80)
|
||||
p = p[1:]
|
||||
}
|
||||
p[0] = uint8(v)
|
||||
p = p[1:]
|
||||
Bwrite(b, buf[:len(buf)-len(p)])
|
||||
Bwrite(b, varintbuf[:len(varintbuf)-len(p)])
|
||||
}
|
||||
|
||||
func wrstring(b *Biobuf, s string) {
|
||||
|
Loading…
Reference in New Issue
Block a user