Fix utostr once and for all, by making there only be one function named
authorChris Lattner <sabre@nondot.org>
Wed, 31 May 2006 21:25:50 +0000 (21:25 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 31 May 2006 21:25:50 +0000 (21:25 +0000)
utostr.  To keep the efficiency in the 32-bit case, make it check to see if
the value is 32-bits and if so switch over to the faster 32-bit case.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28601 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/StringExtras.h

index e66fc693453658e3633f06c1fcb2c8aca6489f38..f54d89ca4644ae2aade5ec1f623d1fbf9743a807 100644 (file)
@@ -39,9 +39,9 @@ static inline std::string utohexstr(uint64_t X) {
   return std::string(BufPtr);
 }
 
-static inline std::string utostr(uint64_t X, bool isNeg = false) {
-  char Buffer[40];
-  char *BufPtr = Buffer+39;
+static inline std::string utostr_32(uint32_t X, bool isNeg = false) {
+  char Buffer[20];
+  char *BufPtr = Buffer+19;
 
   *BufPtr = 0;                  // Null terminate buffer...
   if (X == 0) *--BufPtr = '0';  // Handle special case...
@@ -52,26 +52,30 @@ static inline std::string utostr(uint64_t X, bool isNeg = false) {
   }
 
   if (isNeg) *--BufPtr = '-';   // Add negative sign...
+
   return std::string(BufPtr);
 }
 
-static inline std::string utostr(uint32_t X, bool isNeg = false) {
-  char Buffer[20];
-  char *BufPtr = Buffer+19;
-
+static inline std::string utostr(uint64_t X, bool isNeg = false) {
+  if (X == (uint32_t)X)
+    return utostr_32((uint32_t)X, isNeg);
+  
+  char Buffer[40];
+  char *BufPtr = Buffer+39;
+  
   *BufPtr = 0;                  // Null terminate buffer...
   if (X == 0) *--BufPtr = '0';  // Handle special case...
-
+  
   while (X) {
     *--BufPtr = '0' + char(X % 10);
     X /= 10;
   }
-
+  
   if (isNeg) *--BufPtr = '-';   // Add negative sign...
-
   return std::string(BufPtr);
 }
 
+
 static inline std::string itostr(int64_t X) {
   if (X < 0)
     return utostr(static_cast<uint64_t>(-X), true);
@@ -79,13 +83,6 @@ static inline std::string itostr(int64_t X) {
     return utostr(static_cast<uint64_t>(X));
 }
 
-static inline std::string itostr(int32_t X) {
-  if (X < 0)
-    return utostr(static_cast<unsigned>(-X), true);
-  else
-    return utostr(static_cast<unsigned>(X));
-}
-
 static inline std::string ftostr(double V) {
   char Buffer[200];
   sprintf(Buffer, "%20.6e", V);