]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: don't parse imported packages multiple times.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Wed, 9 Jan 2013 21:03:41 +0000 (22:03 +0100)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Wed, 9 Jan 2013 21:03:41 +0000 (22:03 +0100)
R=dave, golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7068044

src/pkg/go/types/check.go

index 10b67bcab9b583204c4358423ea277bafcfa9452..cebba7abf58f6f6297eac56cd77edc66c716fe81 100644 (file)
@@ -393,7 +393,18 @@ func check(ctxt *Context, fset *token.FileSet, files map[string]*ast.File) (pkg
        // resolve identifiers
        imp := ctxt.Import
        if imp == nil {
-               imp = GcImport
+               // wrap GcImport to import packages only once by default.
+               imported := make(map[string]bool)
+               imp = func(imports map[string]*ast.Object, path string) (*ast.Object, error) {
+                       if imported[path] && imports[path] != nil {
+                               return imports[path], nil
+                       }
+                       pkg, err := GcImport(imports, path)
+                       if err == nil {
+                               imported[path] = true
+                       }
+                       return pkg, err
+               }
        }
        pkg, err = ast.NewPackage(fset, files, imp, Universe)
        if err != nil {