[cfe-commits] r64244 - /cfe/trunk/Driver/PrintPreprocessedOutput.cpp

Chris Lattner sabre at nondot.org
Tue Feb 10 14:16:03 PST 2009


Author: lattner
Date: Tue Feb 10 16:16:03 2009
New Revision: 64244

URL: http://llvm.org/viewvc/llvm-project?rev=64244&view=rev
Log:
use efficient form of getSpelling, this speeds up -dM by 16%.

Modified:
    cfe/trunk/Driver/PrintPreprocessedOutput.cpp

Modified: cfe/trunk/Driver/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/PrintPreprocessedOutput.cpp?rev=64244&r1=64243&r2=64244&view=diff

==============================================================================
--- cfe/trunk/Driver/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/Driver/PrintPreprocessedOutput.cpp Tue Feb 10 16:16:03 2009
@@ -582,11 +582,19 @@
   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";
 }





More information about the cfe-commits mailing list