]> granicus.if.org Git - clang/commitdiff
As a performance optimization, don't bother calling MacroInfo::isIdenticalTo
authorChris Lattner <sabre@nondot.org>
Fri, 16 Jan 2009 19:50:11 +0000 (19:50 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 16 Jan 2009 19:50:11 +0000 (19:50 +0000)
if warnings in system headers are disabled.  isIdenticalTo can end up
calling the expensive getSpelling method, and other bad stuff and is
completely unneeded if the warning will be discarded anyway. rdar://6502956

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62347 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPDirectives.cpp

index a5684cc36a41e5c1302b6f9254a6d394ea0055f3..0566ec54b08cd580a00ed2206bf92803cbd0eb34 100644 (file)
@@ -1060,16 +1060,23 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok) {
   // Finally, if this identifier already had a macro defined for it, verify that
   // the macro bodies are identical and free the old definition.
   if (MacroInfo *OtherMI = getMacroInfo(MacroNameTok.getIdentifierInfo())) {
-    if (!OtherMI->isUsed())
-      Diag(OtherMI->getDefinitionLoc(), diag::pp_macro_not_used);
-
-    // Macros must be identical.  This means all tokes and whitespace separation
-    // must be the same.  C99 6.10.3.2.
-    if (!MI->isIdenticalTo(*OtherMI, *this)) {
-      Diag(MI->getDefinitionLoc(), diag::ext_pp_macro_redef)
-        << MacroNameTok.getIdentifierInfo();
-      Diag(OtherMI->getDefinitionLoc(), diag::note_previous_definition);
+    // It is very common for system headers to have tons of macro redefinitions
+    // and for warnings to be disabled in system headers.  If this is the case,
+    // then don't bother calling MacroInfo::isIdenticalTo.
+    if (!Diags.getSuppressSystemWarnings() ||
+        !SourceMgr.isInSystemHeader(DefineTok.getLocation())) {
+      if (!OtherMI->isUsed())
+        Diag(OtherMI->getDefinitionLoc(), diag::pp_macro_not_used);
+
+      // Macros must be identical.  This means all tokes and whitespace
+      // separation must be the same.  C99 6.10.3.2.
+      if (!MI->isIdenticalTo(*OtherMI, *this)) {
+        Diag(MI->getDefinitionLoc(), diag::ext_pp_macro_redef)
+          << MacroNameTok.getIdentifierInfo();
+        Diag(OtherMI->getDefinitionLoc(), diag::note_previous_definition);
+      }
     }
+    
     ReleaseMacroInfo(OtherMI);
   }