mirror of
https://github.com/golang/go
synced 2024-11-20 04:54:44 -07: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:
parent
a617d06252
commit
11999306df
@ -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
|
||||
};
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user