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>
}
}
+// 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) {