1
0
mirror of https://github.com/golang/go synced 2024-10-03 06:21:21 -06:00

cmd/gc: don't import the same package multiple times.

Implementation suggested by DMorsing.

R=golang-dev, dave, daniel.morsing, rsc
CC=golang-dev
https://golang.org/cl/6903059
This commit is contained in:
Rémy Oudompheng 2012-12-12 08:47:09 +01:00
parent a617d06252
commit 11999306df
2 changed files with 11 additions and 0 deletions

View File

@ -388,6 +388,7 @@ struct Pkg
Sym* pathsym;
char* prefix; // escaped path for use in symbol table
Pkg* link;
uchar imported; // export data of this package was parsed
char exported; // import line written in export data
char direct; // imported directly
};

View File

@ -690,6 +690,16 @@ importfile(Val *f, int line)
}
importpkg = mkpkg(path);
// If we already saw that package, feed a dummy statement
// to the lexer to avoid parsing export data twice.
if(importpkg->imported) {
file = strdup(namebuf);
p = smprint("package %s\n$$\n", importpkg->name);
cannedimports(file, p);
return;
}
importpkg->imported = 1;
imp = Bopen(namebuf, OREAD);
if(imp == nil) {
yyerror("can't open import: \"%Z\": %r", f->u.sval);