]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/ld: cache file name construction in linkgetline
authorRuss Cox <rsc@golang.org>
Wed, 4 Mar 2015 03:29:03 +0000 (22:29 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 5 Mar 2015 02:02:39 +0000 (02:02 +0000)
This avoids repeated allocation and map lookups
when constructing the pcln tables.

For 6g compiling cmd/internal/gc/*.go this saves about 8% wall time.

Change-Id: I6a1a80e278ae2c2a44bd1537015ea7b4e7a4d6ca
Reviewed-on: https://go-review.googlesource.com/6793
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/internal/obj/link.go
src/cmd/internal/obj/obj.go

index 95c9886ab2f196918bfd6f56ce3530e72d741c68..11bebea92497cd8ad7a140653eb59d6066660ca6 100644 (file)
@@ -154,14 +154,6 @@ type Auto struct {
        Gotype  *LSym
 }
 
-type Hist struct {
-       Link    *Hist
-       Name    string
-       Line    int32
-       Offset  int32
-       Printed uint8
-}
-
 type Link struct {
        Thechar            int32
        Thestring          string
index 980a0e4a38c08e931b3845fca0a98caed73c3d4e..ac22fd3f57f267ae8aaa9c95ac10d2e3eceb380e 100644 (file)
@@ -15,6 +15,15 @@ const (
        NSYM   = 50
 )
 
+type Hist struct {
+       Link    *Hist
+       Name    string
+       Sym     *LSym
+       Line    int32
+       Offset  int32
+       Printed uint8
+}
+
 func Linklinefmt(ctxt *Link, lno0 int, showAll, showFullPath bool) string {
        var a [HISTSZ]struct {
                incl *Hist
@@ -174,36 +183,47 @@ func linkgetline(ctxt *Link, line int32, f **LSym, l *int32) {
        n--
        var dlno int32
        var file string
+       var sym *LSym
        if a[n].line != nil {
                file = a[n].line.Name
+               sym = a[n].line.Sym
                dlno = a[n].ldel - 1
        } else {
                file = a[n].incl.Name
+               sym = a[n].incl.Sym
                dlno = a[n].idel - 1
        }
-       var buf string
-       if filepath.IsAbs(file) || strings.HasPrefix(file, "<") {
-               buf = file
-       } else {
-               buf = ctxt.Pathname + "/" + file
-       }
-       // Remove leading ctxt->trimpath, or else rewrite $GOROOT to $GOROOT_FINAL.
-       if ctxt.Trimpath != "" && haspathprefix(buf, ctxt.Trimpath) {
-               if len(buf) == len(ctxt.Trimpath) {
-                       buf = "??"
+       if sym == nil {
+               var buf string
+               if filepath.IsAbs(file) || strings.HasPrefix(file, "<") {
+                       buf = file
                } else {
-                       buf1 := buf[len(ctxt.Trimpath)+1:]
-                       if buf1[0] == '\x00' {
-                               buf1 = "??"
+                       buf = ctxt.Pathname + "/" + file
+               }
+               // Remove leading ctxt->trimpath, or else rewrite $GOROOT to $GOROOT_FINAL.
+               if ctxt.Trimpath != "" && haspathprefix(buf, ctxt.Trimpath) {
+                       if len(buf) == len(ctxt.Trimpath) {
+                               buf = "??"
+                       } else {
+                               buf1 := buf[len(ctxt.Trimpath)+1:]
+                               if buf1[0] == '\x00' {
+                                       buf1 = "??"
+                               }
+                               buf = buf1
                        }
+               } else if ctxt.Goroot_final != "" && haspathprefix(buf, ctxt.Goroot) {
+                       buf1 := fmt.Sprintf("%s%s", ctxt.Goroot_final, buf[len(ctxt.Goroot):])
                        buf = buf1
                }
-       } else if ctxt.Goroot_final != "" && haspathprefix(buf, ctxt.Goroot) {
-               buf1 := fmt.Sprintf("%s%s", ctxt.Goroot_final, buf[len(ctxt.Goroot):])
-               buf = buf1
+               sym = Linklookup(ctxt, buf, HistVersion)
+               if a[n].line != nil {
+                       a[n].line.Sym = sym
+               } else {
+                       a[n].incl.Sym = sym
+               }
        }
        lno -= dlno
-       *f = Linklookup(ctxt, buf, HistVersion)
+       *f = sym
        *l = lno
 }