Commit 873483c6 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

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/9085Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 3c939b53
......@@ -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) {
......
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