r256803 - Avoid walking all the declarations in the TU when a tag is declared in function

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 4 17:21:54 PST 2016


Author: rsmith
Date: Mon Jan  4 19:21:53 2016
New Revision: 256803

URL: http://llvm.org/viewvc/llvm-project?rev=256803&view=rev
Log:
Avoid walking all the declarations in the TU when a tag is declared in function
prototype scope in a function definition.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=256803&r1=256802&r2=256803&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jan  4 19:21:53 2016
@@ -10911,12 +10911,8 @@ Decl *Sema::ActOnStartOfFunctionDef(Scop
       // from the translation unit and reattach to the current context.
       if (D->getLexicalDeclContext() == Context.getTranslationUnitDecl()) {
         // Is the decl actually in the context?
-        for (const auto *DI : Context.getTranslationUnitDecl()->decls()) {
-          if (DI == D) {  
-            Context.getTranslationUnitDecl()->removeDecl(D);
-            break;
-          }
-        }
+        if (Context.getTranslationUnitDecl()->containsDecl(D))
+          Context.getTranslationUnitDecl()->removeDecl(D);
         // Either way, reassign the lexical decl context to our FunctionDecl.
         D->setLexicalDeclContext(CurContext);
       }




More information about the cfe-commits mailing list