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

Chris Lattner sabre at nondot.org
Sun Jul 22 23:31:11 PDT 2007


Author: lattner
Date: Mon Jul 23 01:31:11 2007
New Revision: 40424

URL: http://llvm.org/viewvc/llvm-project?rev=40424&view=rev
Log:
avoid creating std::strings in MoveToLine

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=40424&r1=40423&r2=40424&view=diff

==============================================================================
--- cfe/trunk/Driver/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/Driver/PrintPreprocessedOutput.cpp Mon Jul 23 01:31:11 2007
@@ -148,6 +148,21 @@
 };
 }
 
+/// 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 @@
     
     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());





More information about the cfe-commits mailing list