1
0
mirror of https://github.com/golang/go synced 2024-11-18 19:54:44 -07:00

go.tools/importer: fix classic closing-over-induction-variable gotcha.

Now we actually prefetch all n packages, instead of
prefetching the last one n times.  This yields a further 22%
improvement, which is more like what I was hoping for.

It makes me so sad that Go reproduced one of the best-known
mistakes of JavaScript.  D'oh!

R=crawshaw
CC=golang-dev
https://golang.org/cl/13379046
This commit is contained in:
Alan Donovan 2013-09-04 14:32:36 -04:00
parent e2921e188a
commit f5ac829804

View File

@ -177,7 +177,7 @@ func (imp *Importer) LoadPackage(importPath string) (*PackageInfo, error) {
if files, err := loadPackage(imp.config.Build, imp.Fset, importPath); err == nil { if files, err := loadPackage(imp.config.Build, imp.Fset, importPath); err == nil {
// Kick off asynchronous I/O and parsing for the imports. // Kick off asynchronous I/O and parsing for the imports.
for path := range imports(importPath, files) { for path := range imports(importPath, files) {
go func() { imp.LoadPackage(path) }() go func(path string) { imp.LoadPackage(path) }(path)
} }
// Type-check the package. // Type-check the package.