Commit 36f25a7e authored by David Crawshaw's avatar David Crawshaw

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/20027Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent f4717a90
......@@ -431,9 +431,23 @@ func rdstring(f *obj.Biobuf) string {
return string(p)
}
var (
rddataBuf = make([]byte, rddataBufMax)
rddataBufMax = 1 << 14
)
func rddata(f *obj.Biobuf) []byte {
n := rdint64(f)
p := make([]byte, n)
var p []byte
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)
return p
}
......
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