cmd/internal/gc: replace hash tables with Go maps
The C version of the compiler had just one hash table,
indexed by a (name string, pkg *Pkg) pair.
Because we always know the pkg during a lookup,
replace the one table with a per-Pkg map[string]*Sym.
This also lets us do non-allocating []byte key lookups.
This CL *does* change the generated object files.
In the old code, export data and init calls were emitted
in "hash table order". Now they are emitted in the order
in which they were added to the table.
Change-Id: I5a48d5c9add996dc43ad04a905641d901522de0b
Reviewed-on: https://go-review.googlesource.com/6600
Reviewed-by: Rob Pike <r@golang.org>
diff --git a/src/cmd/internal/gc/export.go b/src/cmd/internal/gc/export.go
index 54ed515..e36ea76 100644
--- a/src/cmd/internal/gc/export.go
+++ b/src/cmd/internal/gc/export.go
@@ -372,12 +372,9 @@
}
fmt.Fprintf(bout, "\n")
- var p *Pkg
- for i := int32(0); i < int32(len(phash)); i++ {
- for p = phash[i]; p != nil; p = p.Link {
- if p.Direct != 0 {
- dumppkg(p)
- }
+ for _, p := range pkgs {
+ if p.Direct != 0 {
+ dumppkg(p)
}
}
@@ -432,6 +429,8 @@
return s.Def.Type
}
+var numImport = make(map[string]int)
+
func importimport(s *Sym, path string) {
// Informational: record package name
// associated with import path, for use in
@@ -443,7 +442,7 @@
p := mkpkg(path)
if p.Name == "" {
p.Name = s.Name
- Pkglookup(s.Name, nil).Npkg++
+ numImport[s.Name]++
} else if p.Name != s.Name {
Yyerror("conflicting names %s and %s for package %q", p.Name, s.Name, p.Path)
}