As a performance optimization, don't bother calling MacroInfo::isIdenticalTo 
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
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index a5684cc..0566ec5 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -1060,16 +1060,23 @@
   // 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);
+    // 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);
+      // 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);
   }