]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: don't import the same package multiple times.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Wed, 12 Dec 2012 07:47:09 +0000 (08:47 +0100)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Wed, 12 Dec 2012 07:47:09 +0000 (08:47 +0100)
Implementation suggested by DMorsing.

R=golang-dev, dave, daniel.morsing, rsc
CC=golang-dev
https://golang.org/cl/6903059

src/cmd/gc/go.h
src/cmd/gc/lex.c

index 0280c965c920d9f4b9e58c41bf912a4eeae38694..36bc4b2954744c7397ebc9b1798eca59a977ac40 100644 (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
 };
index 6481ceb1e1073330132ad5aa0132d1df56b157ad..eabeaeb646971e7c7d2c2be2af83d65f3d934e76 100644 (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);