From: Rémy Oudompheng Date: Wed, 12 Dec 2012 07:47:09 +0000 (+0100) Subject: cmd/gc: don't import the same package multiple times. X-Git-Tag: go1.1rc2~1657 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=11999306df8b02dbbf26ac0772429c8ca5754ab5;p=gostls13.git 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 --- diff --git a/src/cmd/gc/go.h b/src/cmd/gc/go.h index 0280c965c9..36bc4b2954 100644 --- a/src/cmd/gc/go.h +++ b/src/cmd/gc/go.h @@ -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 }; diff --git a/src/cmd/gc/lex.c b/src/cmd/gc/lex.c index 6481ceb1e1..eabeaeb646 100644 --- a/src/cmd/gc/lex.c +++ b/src/cmd/gc/lex.c @@ -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);