]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj: use map for symbol table
authorRuss Cox <rsc@golang.org>
Mon, 9 Mar 2015 02:45:13 +0000 (22:45 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 16 Mar 2015 23:07:22 +0000 (23:07 +0000)
Change-Id: I105c1e7730c1e7ccf36297b9cbf96dc0a4868013
Reviewed-on: https://go-review.googlesource.com/7621
Reviewed-by: Rob Pike <r@golang.org>
src/cmd/internal/obj/link.go
src/cmd/internal/obj/sym.go

index ea38f54ebbeffad35076012e414fd7d54e236a8a..caa24e02abfe48c47b23d8506bba19cccfe4f9d8 100644 (file)
@@ -115,7 +115,6 @@ type LSym struct {
        Locals      int32
        Value       int64
        Size        int64
-       Hash        *LSym
        Allsym      *LSym
        Next        *LSym
        Sub         *LSym
@@ -181,7 +180,7 @@ type Link struct {
        Goroot             string
        Goroot_final       string
        Enforce_data_order int32
-       Hash               [LINKHASH]*LSym
+       Hash               map[SymVer]*LSym
        Allsym             *LSym
        Nsymbol            int32
        Hist               *Hist
@@ -226,6 +225,11 @@ type Link struct {
        Filesyms           *LSym
 }
 
+type SymVer struct {
+       Name    string
+       Version int
+}
+
 type Plist struct {
        Name    *LSym
        Firstpc *Prog
@@ -539,10 +543,6 @@ const (
        A_PARAM
 )
 
-const (
-       LINKHASH = 100003
-)
-
 // Pcdata iterator.
 //     for(pciterinit(ctxt, &it, &pcd); !it.done; pciternext(&it)) { it.value holds in [it.pc, it.nextpc) }
 
index 1557446457560dbf19411c1ea08c59ed7068df0d..7d9e469da73691664b9f654b40a158b8785028a8 100644 (file)
@@ -126,6 +126,7 @@ func Linknew(arch *LinkArch) *Link {
        linksetexp()
 
        ctxt := new(Link)
+       ctxt.Hash = make(map[SymVer]*LSym)
        ctxt.Arch = arch
        ctxt.Version = HistVersion
        ctxt.Goroot = Getgoroot()
@@ -241,26 +242,14 @@ func linknewsym(ctxt *Link, symb string, v int) *LSym {
 }
 
 func _lookup(ctxt *Link, symb string, v int, creat int) *LSym {
-       h := uint32(v)
-       for i := 0; i < len(symb); i++ {
-               c := int(symb[i])
-               h = h + h + h + uint32(c)
-       }
-       h &= 0xffffff
-       h %= LINKHASH
-       for s := ctxt.Hash[h]; s != nil; s = s.Hash {
-               if int(s.Version) == v && s.Name == symb {
-                       return s
-               }
-       }
-       if creat == 0 {
-               return nil
+       s := ctxt.Hash[SymVer{symb, v}]
+       if s != nil || creat == 0 {
+               return s
        }
 
-       s := linknewsym(ctxt, symb, v)
+       s = linknewsym(ctxt, symb, v)
        s.Extname = s.Name
-       s.Hash = ctxt.Hash[h]
-       ctxt.Hash[h] = s
+       ctxt.Hash[SymVer{symb, v}] = s
 
        return s
 }