diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2010-02-27 18:02:51 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2010-02-27 18:02:51 +0000 |
commit | e396007efa010568d7ac7dff15762aec7653fc63 (patch) | |
tree | ae6eb7285f5487423b3a69c985418a4397f2ab4e /lib/Frontend/PrintPreprocessedOutput.cpp | |
parent | 51f5fe3f2527cd1640d798d8d134268b14de3e86 (diff) |
Revert 97324. Chris says this cleanup could hurt -E performance.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97331 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/PrintPreprocessedOutput.cpp')
-rw-r--r-- | lib/Frontend/PrintPreprocessedOutput.cpp | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/lib/Frontend/PrintPreprocessedOutput.cpp b/lib/Frontend/PrintPreprocessedOutput.cpp index beba26013e..774372c869 100644 --- a/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/lib/Frontend/PrintPreprocessedOutput.cpp @@ -390,7 +390,7 @@ struct UnknownPragmaHandler : public PragmaHandler { 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 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok, 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; |