From f063721c4b1c5f2fd82bcbe2ef86fe4f61d21111 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 23 Jul 2007 06:31:11 +0000 Subject: [PATCH] avoid creating std::strings in MoveToLine git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@40424 91177308-0d34-0410-b5e6-96231b3b80d8 --- Driver/PrintPreprocessedOutput.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Driver/PrintPreprocessedOutput.cpp b/Driver/PrintPreprocessedOutput.cpp index e5f449185a..87180f455e 100644 --- a/Driver/PrintPreprocessedOutput.cpp +++ b/Driver/PrintPreprocessedOutput.cpp @@ -148,6 +148,21 @@ public: }; } +/// UToStr - Do itoa on the specified number, in-place in the specified buffer. +/// endptr points to the end of the buffer. +static char *UToStr(unsigned N, char *EndPtr) { + // Null terminate the buffer. + *--EndPtr = '\0'; + if (N == 0) // Zero is a special case. + *--EndPtr = '0'; + while (N) { + *--EndPtr = '0' + char(N % 10); + N /= 10; + } + return EndPtr; +} + + /// MoveToLine - Move the output to the source line specified by the location /// object. We can do this by emitting some number of \n's, or be emitting a /// #line directive. @@ -182,8 +197,9 @@ void PrintPPOutputPPCallbacks::MoveToLine(SourceLocation Loc) { OutputChar('#'); OutputChar(' '); - std::string Num = llvm::utostr_32(LineNo); - OutputString(&Num[0], Num.size()); + char NumberBuffer[20]; + const char *NumStr = UToStr(LineNo, NumberBuffer+20); + OutputString(NumStr, (NumberBuffer+20)-NumStr-1); OutputChar(' '); OutputChar('"'); OutputString(&CurFilename[0], CurFilename.size()); -- 2.50.1