aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-05-31 21:25:50 +0000
committerChris Lattner <sabre@nondot.org>2006-05-31 21:25:50 +0000
commit6fb568f77e6766871ad07b3b206571e96b56dfb5 (patch)
treeaf5e435c1a75e67126f7c920ee883d3e95aa2001
parent13d4ab4009822699f7546706bbc049cd8820d30a (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28601 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/ADT/StringExtras.h31
1 files changed, 14 insertions, 17 deletions
diff --git a/include/llvm/ADT/StringExtras.h b/include/llvm/ADT/StringExtras.h
index e66fc69345..f54d89ca46 100644
--- a/include/llvm/ADT/StringExtras.h
+++ b/include/llvm/ADT/StringExtras.h
@@ -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);