llvm.org GIT mirror llvm / 6fb568f
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 Chris Lattner 14 years ago
1 changed file(s) with 21 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
3838 return std::string(BufPtr);
3939 }
4040
41 static inline std::string utostr(uint64_t X, bool isNeg = false) {
42 char Buffer[40];
43 char *BufPtr = Buffer+39;
44
45 *BufPtr = 0; // Null terminate buffer...
46 if (X == 0) *--BufPtr = '0'; // Handle special case...
47
48 while (X) {
49 *--BufPtr = '0' + char(X % 10);
50 X /= 10;
51 }
52
53 if (isNeg) *--BufPtr = '-'; // Add negative sign...
54 return std::string(BufPtr);
55 }
56
57 static inline std::string utostr(uint32_t X, bool isNeg = false) {
41 static inline std::string utostr_32(uint32_t X, bool isNeg = false) {
5842 char Buffer[20];
5943 char *BufPtr = Buffer+19;
6044
7155 return std::string(BufPtr);
7256 }
7357
58 static inline std::string utostr(uint64_t X, bool isNeg = false) {
59 if (X == (uint32_t)X)
60 return utostr_32((uint32_t)X, isNeg);
61
62 char Buffer[40];
63 char *BufPtr = Buffer+39;
64
65 *BufPtr = 0; // Null terminate buffer...
66 if (X == 0) *--BufPtr = '0'; // Handle special case...
67
68 while (X) {
69 *--BufPtr = '0' + char(X % 10);
70 X /= 10;
71 }
72
73 if (isNeg) *--BufPtr = '-'; // Add negative sign...
74 return std::string(BufPtr);
75 }
76
77
7478 static inline std::string itostr(int64_t X) {
7579 if (X < 0)
7680 return utostr(static_cast(-X), true);
7781 else
7882 return utostr(static_cast(X));
79 }
80
81 static inline std::string itostr(int32_t X) {
82 if (X < 0)
83 return utostr(static_cast(-X), true);
84 else
85 return utostr(static_cast(X));
8683 }
8784
8885 static inline std::string ftostr(double V) {