Commit 35049450 authored by Shahar Kohanim's avatar Shahar Kohanim Committed by David Crawshaw

cmd/link: optimize int parsing

Speeds up linking cmd/go by ~1.5%:

name       old s/op   new s/op   delta
LinkCmdGo  0.58 ± 6%  0.57 ± 5%  -1.21%  (p=0.000 n=98+99)

Less noisy benchmark, with garbage collection off:

name       old s/op   new s/op   delta
LinkCmdGo  0.49 ± 2%  0.49 ± 2%  -1.79%  (p=0.000 n=98+99)

Change-Id: I0123bcb66a87cbc4d703356e4c5a4035032012ec
Reviewed-on: https://go-review.googlesource.com/20916Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 8d9ece9d
...@@ -33,6 +33,8 @@ type Biobuf struct { ...@@ -33,6 +33,8 @@ type Biobuf struct {
linelen int linelen int
} }
func (b *Biobuf) Reader() *bufio.Reader { return b.r }
func Bopenw(name string) (*Biobuf, error) { func Bopenw(name string) (*Biobuf, error) {
f, err := os.Create(name) f, err := os.Create(name)
if err != nil { if err != nil {
......
...@@ -395,15 +395,17 @@ func readref(ctxt *Link, f *obj.Biobuf, pkg string, pn string) { ...@@ -395,15 +395,17 @@ func readref(ctxt *Link, f *obj.Biobuf, pkg string, pn string) {
} }
func rdint64(f *obj.Biobuf) int64 { func rdint64(f *obj.Biobuf) int64 {
var c int r := f.Reader()
uv := uint64(0) uv := uint64(0)
for shift := 0; ; shift += 7 { for shift := uint(0); ; shift += 7 {
if shift >= 64 { if shift >= 64 {
log.Fatalf("corrupt input") log.Fatalf("corrupt input")
} }
c = obj.Bgetc(f) c, err := r.ReadByte()
uv |= uint64(c&0x7F) << uint(shift) if err != nil {
log.Fatalln("error reading input: ", err)
}
uv |= uint64(c&0x7F) << shift
if c&0x80 == 0 { if c&0x80 == 0 {
break break
} }
......
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