mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-03 19:02:35 +00:00
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. llvm-svn: 28601
This commit is contained in:
parent
36f99c7c1d
commit
2429ec5fdf
@ -39,23 +39,7 @@ 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;
|
||||
|
||||
*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 utostr(uint32_t X, bool isNeg = false) {
|
||||
static inline std::string utostr_32(uint32_t X, bool isNeg = false) {
|
||||
char Buffer[20];
|
||||
char *BufPtr = Buffer+19;
|
||||
|
||||
@ -72,6 +56,26 @@ static inline std::string utostr(uint32_t X, bool isNeg = false) {
|
||||
return std::string(BufPtr);
|
||||
}
|
||||
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user