1
0
mirror of https://github.com/golang/go synced 2024-11-13 18:00:30 -07:00

cmd/link: allocate small []byte reads together

Reduces number of memory allocations by 12%:

Before: 1816664
After:  1581591

Small speed improvement.

Change-Id: I61281fb852e8e31851a350e3ae756676705024a4
Reviewed-on: https://go-review.googlesource.com/20027
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
David Crawshaw 2016-02-28 17:58:57 -09:00
parent f4717a902e
commit 36f25a7e7b

View File

@ -431,9 +431,23 @@ func rdstring(f *obj.Biobuf) string {
return string(p) return string(p)
} }
var (
rddataBuf = make([]byte, rddataBufMax)
rddataBufMax = 1 << 14
)
func rddata(f *obj.Biobuf) []byte { func rddata(f *obj.Biobuf) []byte {
n := rdint64(f) var p []byte
p := make([]byte, n) n := rdint(f)
if n > rddataBufMax {
p = make([]byte, n)
} else {
if len(rddataBuf) < n {
rddataBuf = make([]byte, rddataBufMax)
}
p = rddataBuf[:n:n]
rddataBuf = rddataBuf[n:]
}
obj.Bread(f, p) obj.Bread(f, p)
return p return p
} }