]> granicus.if.org Git - clang/commitdiff
use efficient form of getSpelling, this speeds up -dM by 16%.
authorChris Lattner <sabre@nondot.org>
Tue, 10 Feb 2009 22:16:03 +0000 (22:16 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 10 Feb 2009 22:16:03 +0000 (22:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64244 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/PrintPreprocessedOutput.cpp

index 8bd4e96ae3bafc8f211b2c6a9c8731e54ce42703..7aceb7a750285c1dce6a4d2d5ee3d18a2bac5c5c 100644 (file)
@@ -582,11 +582,19 @@ static void PrintMacroDefinition(IdentifierInfo &II, const MacroInfo &MI,
   if (MI.tokens_empty() || !MI.tokens_begin()->hasLeadingSpace())
     OS << ' ';
   
+  llvm::SmallVector<char, 128> SpellingBuffer;
+  
   for (MacroInfo::tokens_iterator I = MI.tokens_begin(), E = MI.tokens_end();
        I != E; ++I) {
     if (I->hasLeadingSpace())
       OS << ' ';
-    OS << PP.getSpelling(*I);
+    
+    // Make sure we have enough space in the spelling buffer.
+    if (I->getLength() < SpellingBuffer.size())
+      SpellingBuffer.resize(I->getLength());
+    const char *Buffer = &SpellingBuffer[0];
+    unsigned SpellingLen = PP.getSpelling(*I, Buffer);
+    OS.write(Buffer, SpellingLen);
   }
   OS << "\n";
 }