[cfe-commits] r97331 - /cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp

Benjamin Kramer benny.kra at googlemail.com
Sat Feb 27 10:02:51 PST 2010


Author: d0k
Date: Sat Feb 27 12:02:51 2010
New Revision: 97331

URL: http://llvm.org/viewvc/llvm-project?rev=97331&view=rev
Log:
Revert 97324. Chris says this cleanup could hurt -E performance.

Modified:
    cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp

Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=97331&r1=97330&r2=97331&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Sat Feb 27 12:02:51 2010
@@ -390,7 +390,7 @@
 static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
                                     PrintPPOutputPPCallbacks *Callbacks,
                                     llvm::raw_ostream &OS) {
-  llvm::SmallString<256> Buffer;
+  char Buffer[256];
   Token PrevTok;
   while (1) {
 
@@ -406,13 +406,29 @@
       OS << ' ';
     }
 
-    llvm::StringRef Str = PP.getSpelling(Tok, Buffer);
-    OS << Str;
-    // Tokens that can contain embedded newlines need to adjust our current
-    // line number.
-    if (Tok.getKind() == tok::comment)
-      Callbacks->HandleNewlinesInToken(Str.data(), Str.size());
-
+    if (IdentifierInfo *II = Tok.getIdentifierInfo()) {
+      OS << II->getName();
+    } else if (Tok.isLiteral() && !Tok.needsCleaning() &&
+               Tok.getLiteralData()) {
+      OS.write(Tok.getLiteralData(), Tok.getLength());
+    } else if (Tok.getLength() < 256) {
+      const char *TokPtr = Buffer;
+      unsigned Len = PP.getSpelling(Tok, TokPtr);
+      OS.write(TokPtr, Len);
+
+      // Tokens that can contain embedded newlines need to adjust our current
+      // line number.
+      if (Tok.getKind() == tok::comment)
+        Callbacks->HandleNewlinesInToken(TokPtr, Len);
+    } else {
+      std::string S = PP.getSpelling(Tok);
+      OS.write(&S[0], S.size());
+
+      // Tokens that can contain embedded newlines need to adjust our current
+      // line number.
+      if (Tok.getKind() == tok::comment)
+        Callbacks->HandleNewlinesInToken(&S[0], S.size());
+    }
     Callbacks->SetEmittedTokensOnThisLine();
 
     if (Tok.is(tok::eof)) break;





More information about the cfe-commits mailing list