]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: optimize int parsing
authorShahar Kohanim <skohanim@gmail.com>
Sat, 19 Mar 2016 21:27:41 +0000 (23:27 +0200)
committerDavid Crawshaw <crawshaw@golang.org>
Sun, 20 Mar 2016 13:10:33 +0000 (13:10 +0000)
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/20916
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/internal/obj/util.go
src/cmd/link/internal/ld/objfile.go

index 18450962edacd001f0c79be3ae5ba4d1e5070f2b..b04b1a55d45d538c27d4f04708d9f1bb23c92ac3 100644 (file)
@@ -33,6 +33,8 @@ type Biobuf struct {
        linelen int
 }
 
+func (b *Biobuf) Reader() *bufio.Reader { return b.r }
+
 func Bopenw(name string) (*Biobuf, error) {
        f, err := os.Create(name)
        if err != nil {
index 21b9d6e8209664fcf0b4ec4faba00346b414227f..c98080f57f4a1d08caadae7f4b5ef2c0da7f0ed5 100644 (file)
@@ -395,15 +395,17 @@ func readref(ctxt *Link, f *obj.Biobuf, pkg string, pn string) {
 }
 
 func rdint64(f *obj.Biobuf) int64 {
-       var c int
-
+       r := f.Reader()
        uv := uint64(0)
-       for shift := 0; ; shift += 7 {
+       for shift := uint(0); ; shift += 7 {
                if shift >= 64 {
                        log.Fatalf("corrupt input")
                }
-               c = obj.Bgetc(f)
-               uv |= uint64(c&0x7F) << uint(shift)
+               c, err := r.ReadByte()
+               if err != nil {
+                       log.Fatalln("error reading input: ", err)
+               }
+               uv |= uint64(c&0x7F) << shift
                if c&0x80 == 0 {
                        break
                }