Commit c0f7195d authored by David Crawshaw's avatar David Crawshaw

cmd/link: replace custom hashmap in DWARF writer

Also stop creating a map for each symbol, as it does not seem to help.

Linking juju:
	tip:  real 0m5.470s user 0m6.131s
	this: real 0m4.811s user 0m5.582s

Change-Id: Ib3d931c996396a00942581770ff32df1eb8d6615
Reviewed-on: https://go-review.googlesource.com/20140
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 97b2295f
...@@ -485,18 +485,6 @@ func writeabbrev() { ...@@ -485,18 +485,6 @@ func writeabbrev() {
/* /*
* Debugging Information Entries and their attributes. * Debugging Information Entries and their attributes.
*/ */
const (
HASHSIZE = 107
)
func dwarfhashstr(s string) uint32 {
h := uint32(0)
for s != "" {
h = h + h + h + uint32(s[0])
s = s[1:]
}
return h % HASHSIZE
}
// For DW_CLS_string and _block, value should contain the length, and // For DW_CLS_string and _block, value should contain the length, and
// data the data, for _reference, value is 0 and data is a DWDie* to // data the data, for _reference, value is 0 and data is a DWDie* to
...@@ -518,9 +506,8 @@ type DWDie struct { ...@@ -518,9 +506,8 @@ type DWDie struct {
attr *DWAttr attr *DWAttr
// offset into .debug_info section, i.e relative to // offset into .debug_info section, i.e relative to
// infoo. only valid after call to putdie() // infoo. only valid after call to putdie()
offs int64 offs int64
hash []*DWDie // optional index of children by name, enabled by mkindex() hash map[string]*DWDie // optional index of DWAttr by name, enabled by mkindex()
hlink *DWDie // bucket chain in parent's index
} }
/* /*
...@@ -580,16 +567,14 @@ func newdie(parent *DWDie, abbrev int, name string) *DWDie { ...@@ -580,16 +567,14 @@ func newdie(parent *DWDie, abbrev int, name string) *DWDie {
newattr(die, DW_AT_name, DW_CLS_STRING, int64(len(name)), name) newattr(die, DW_AT_name, DW_CLS_STRING, int64(len(name)), name)
if parent.hash != nil { if parent.hash != nil {
h := int(dwarfhashstr(name)) parent.hash[name] = die
die.hlink = parent.hash[h]
parent.hash[h] = die
} }
return die return die
} }
func mkindex(die *DWDie) { func mkindex(die *DWDie) {
die.hash = make([]*DWDie, HASHSIZE) die.hash = make(map[string]*DWDie)
} }
func walktypedef(die *DWDie) *DWDie { func walktypedef(die *DWDie) *DWDie {
...@@ -610,7 +595,6 @@ func walktypedef(die *DWDie) *DWDie { ...@@ -610,7 +595,6 @@ func walktypedef(die *DWDie) *DWDie {
func find(die *DWDie, name string) *DWDie { func find(die *DWDie, name string) *DWDie {
var prev *DWDie var prev *DWDie
for ; die != prev; prev, die = die, walktypedef(die) { for ; die != prev; prev, die = die, walktypedef(die) {
if die.hash == nil { if die.hash == nil {
for a := die.child; a != nil; a = a.link { for a := die.child; a != nil; a = a.link {
if name == getattr(a, DW_AT_name).data { if name == getattr(a, DW_AT_name).data {
...@@ -619,28 +603,9 @@ func find(die *DWDie, name string) *DWDie { ...@@ -619,28 +603,9 @@ func find(die *DWDie, name string) *DWDie {
} }
continue continue
} }
if a := die.hash[name]; a != nil {
h := int(dwarfhashstr(name))
a := die.hash[h]
if a == nil {
continue
}
if name == getattr(a, DW_AT_name).data {
return a return a
} }
// Move found ones to head of the list.
for b := a.hlink; b != nil; b = b.hlink {
if name == getattr(b, DW_AT_name).data {
a.hlink = b.hlink
b.hlink = die.hash[h]
die.hash[h] = b
return b
}
a = b
}
} }
return nil return nil
} }
...@@ -1621,12 +1586,9 @@ func writelines() { ...@@ -1621,12 +1586,9 @@ func writelines() {
} }
var ( var (
dt int dt, da int
offs int64 offs int64
varhash [HASHSIZE]*DWDie
) )
da := 0
dwfunc.hash = varhash[:] // enable indexing of children by name
for a := s.Autom; a != nil; a = a.Link { for a := s.Autom; a != nil; a = a.Link {
switch a.Name { switch a.Name {
case obj.A_AUTO: case obj.A_AUTO:
...@@ -1678,8 +1640,6 @@ func writelines() { ...@@ -1678,8 +1640,6 @@ func writelines() {
da++ da++
} }
dwfunc.hash = nil
} }
flushunit(dwinfo, epc, epcs, unitstart, int32(headerend-unitstart-10)) flushunit(dwinfo, epc, epcs, unitstart, int32(headerend-unitstart-10))
......
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