From: Chris Lattner Date: Wed, 31 May 2006 21:25:50 +0000 (+0000) Subject: Fix utostr once and for all, by making there only be one function named X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=6fb568f77e6766871ad07b3b206571e96b56dfb5;p=oota-llvm.git 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 --- diff --git a/include/llvm/ADT/StringExtras.h b/include/llvm/ADT/StringExtras.h index e66fc693453..f54d89ca464 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(-X), true); @@ -79,13 +83,6 @@ static inline std::string itostr(int64_t X) { return utostr(static_cast(X)); } -static inline std::string itostr(int32_t X) { - if (X < 0) - return utostr(static_cast(-X), true); - else - return utostr(static_cast(X)); -} - static inline std::string ftostr(double V) { char Buffer[200]; sprintf(Buffer, "%20.6e", V);