[llvm-commits] CVS: llvm/include/llvm/ADT/StringExtras.h
Chris Lattner
lattner at cs.uiuc.edu
Wed May 31 14:26:02 PDT 2006
Changes in directory llvm/include/llvm/ADT:
StringExtras.h updated: 1.31 -> 1.32
---
Log message:
Fix utostr once and for all, by making there only be one function named
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.
---
Diffs of the changes: (+14 -17)
StringExtras.h | 31 ++++++++++++++-----------------
1 files changed, 14 insertions(+), 17 deletions(-)
Index: llvm/include/llvm/ADT/StringExtras.h
diff -u llvm/include/llvm/ADT/StringExtras.h:1.31 llvm/include/llvm/ADT/StringExtras.h:1.32
--- llvm/include/llvm/ADT/StringExtras.h:1.31 Wed May 31 15:18:27 2006
+++ llvm/include/llvm/ADT/StringExtras.h Wed May 31 16:25:50 2006
@@ -39,9 +39,9 @@
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 @@
}
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 @@
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);
More information about the llvm-commits
mailing list