Commit 11999306 authored by Rémy Oudompheng's avatar Rémy Oudompheng

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
parent a617d062
...@@ -388,6 +388,7 @@ struct Pkg ...@@ -388,6 +388,7 @@ struct Pkg
Sym* pathsym; Sym* pathsym;
char* prefix; // escaped path for use in symbol table char* prefix; // escaped path for use in symbol table
Pkg* link; Pkg* link;
uchar imported; // export data of this package was parsed
char exported; // import line written in export data char exported; // import line written in export data
char direct; // imported directly char direct; // imported directly
}; };
......
...@@ -690,6 +690,16 @@ importfile(Val *f, int line) ...@@ -690,6 +690,16 @@ importfile(Val *f, int line)
} }
importpkg = mkpkg(path); 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); imp = Bopen(namebuf, OREAD);
if(imp == nil) { if(imp == nil) {
yyerror("can't open import: \"%Z\": %r", f->u.sval); yyerror("can't open import: \"%Z\": %r", f->u.sval);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment