mirror of
https://github.com/golang/go
synced 2024-11-13 18:20:32 -07:00
go/internal/gccgoimporter: use a slice instead of a map for type map (optimization)
ggcgo's export format numbers types consecutively, starting at 1. This makes it trivially possible to use a slice (list) instead of map for the internal types map. Change-Id: Ib7814d7fabffac0ad2b56f04a5dad7d6d4c4dd0e Reviewed-on: https://go-review.googlesource.com/137935 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
9c81402f58
commit
d1594055cc
@ -26,7 +26,7 @@ type parser struct {
|
|||||||
pkgname string // name of imported package
|
pkgname string // name of imported package
|
||||||
pkg *types.Package // reference to imported package
|
pkg *types.Package // reference to imported package
|
||||||
imports map[string]*types.Package // package path -> package object
|
imports map[string]*types.Package // package path -> package object
|
||||||
typeMap map[int]types.Type // type number -> type
|
typeList []types.Type // type number -> type
|
||||||
initdata InitData // package init priority data
|
initdata InitData // package init priority data
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ func (p *parser) init(filename string, src io.Reader, imports map[string]*types.
|
|||||||
p.scanner.Filename = filename // for good error messages
|
p.scanner.Filename = filename // for good error messages
|
||||||
p.next()
|
p.next()
|
||||||
p.imports = imports
|
p.imports = imports
|
||||||
p.typeMap = make(map[int]types.Type)
|
p.typeList = make([]types.Type, 1 /* type numbers start at 1 */, 16)
|
||||||
}
|
}
|
||||||
|
|
||||||
type importError struct {
|
type importError struct {
|
||||||
@ -387,19 +387,19 @@ var reserved = new(struct{ types.Type })
|
|||||||
|
|
||||||
// reserve reserves the type map entry n for future use.
|
// reserve reserves the type map entry n for future use.
|
||||||
func (p *parser) reserve(n int) {
|
func (p *parser) reserve(n int) {
|
||||||
if p.typeMap[n] != nil {
|
if n != len(p.typeList) {
|
||||||
p.errorf("internal error: type %d already used", n)
|
p.errorf("invalid type number %d (out of sync)", n)
|
||||||
}
|
}
|
||||||
p.typeMap[n] = reserved
|
p.typeList = append(p.typeList, reserved)
|
||||||
}
|
}
|
||||||
|
|
||||||
// update sets the type map entries for the given type numbers nlist to t.
|
// update sets the type map entries for the given type numbers nlist to t.
|
||||||
func (p *parser) update(t types.Type, nlist []int) {
|
func (p *parser) update(t types.Type, nlist []int) {
|
||||||
for _, n := range nlist {
|
for _, n := range nlist {
|
||||||
if p.typeMap[n] != reserved {
|
if p.typeList[n] != reserved {
|
||||||
p.errorf("internal error: typeMap[%d] not reserved", n)
|
p.errorf("typeMap[%d] not reserved", n)
|
||||||
}
|
}
|
||||||
p.typeMap[n] = t
|
p.typeList[n] = t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -790,11 +790,8 @@ func (p *parser) parseType(pkg *types.Package, n ...int) (t types.Type) {
|
|||||||
case scanner.Int:
|
case scanner.Int:
|
||||||
n1 := p.parseInt()
|
n1 := p.parseInt()
|
||||||
if p.tok == '>' {
|
if p.tok == '>' {
|
||||||
t = p.typeMap[n1]
|
t = p.typeList[n1]
|
||||||
switch t {
|
if t == reserved {
|
||||||
case nil:
|
|
||||||
p.errorf("invalid type number, type %d not yet declared", n1)
|
|
||||||
case reserved:
|
|
||||||
p.errorf("invalid type cycle, type %d not yet defined", n1)
|
p.errorf("invalid type cycle, type %d not yet defined", n1)
|
||||||
}
|
}
|
||||||
p.update(t, n)
|
p.update(t, n)
|
||||||
@ -986,7 +983,7 @@ func (p *parser) parsePackage() *types.Package {
|
|||||||
for p.tok != scanner.EOF {
|
for p.tok != scanner.EOF {
|
||||||
p.parseDirective()
|
p.parseDirective()
|
||||||
}
|
}
|
||||||
for _, typ := range p.typeMap {
|
for _, typ := range p.typeList {
|
||||||
if it, ok := typ.(*types.Interface); ok {
|
if it, ok := typ.(*types.Interface); ok {
|
||||||
it.Complete()
|
it.Complete()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user