From e5fbc6c85d98f91357f6f8bfd19c67e96c4f143f Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 18 May 2012 19:32:16 +0000 Subject: Lexer::ReadToEndOfLine: Only build the string if it's actually used and do so in a less malloc-intensive way. llvm-svn: 157064 --- clang/lib/Lex/PPDirectives.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'clang/lib/Lex/PPDirectives.cpp') diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 625a204af99..c6290170892 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -1018,15 +1018,13 @@ void Preprocessor::HandleUserDiagnosticDirective(Token &Tok, // tokens. For example, this is allowed: "#warning ` 'foo". GCC does // collapse multiple consequtive white space between tokens, but this isn't // specified by the standard. - std::string Message = CurLexer->ReadToEndOfLine(); + SmallString<128> Message; + CurLexer->ReadToEndOfLine(&Message); // Find the first non-whitespace character, so that we can make the // diagnostic more succinct. - StringRef Msg(Message); - size_t i = Msg.find_first_not_of(' '); - if (i < Msg.size()) - Msg = Msg.substr(i); - + StringRef Msg = Message.str().ltrim(" "); + if (isWarning) Diag(Tok, diag::pp_hash_warning) << Msg; else -- cgit v1.2.3