llvm.org GIT mirror llvm / 2b95044
Merge utohex_buffer into utohexstr, it's only caller. Also change utohexstr to use the std::string constructor that takes a start and end pointer. This saves a call to strlen. NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@259329 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 4 years ago
1 changed file(s) with 6 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
4343 return -1U;
4444 }
4545
46 /// utohex_buffer - Emit the specified number into the buffer specified by
47 /// BufferEnd, returning a pointer to the start of the string. This can be used
48 /// like this: (note that the buffer must be large enough to handle any number):
49 /// char Buffer[40];
50 /// printf("0x%s", utohex_buffer(X, Buffer+40));
51 ///
52 /// This should only be used with unsigned types.
53 ///
54 template
55 static inline char *utohex_buffer(IntTy X, char *BufferEnd, bool LowerCase = false) {
56 char *BufPtr = BufferEnd;
57 *--BufPtr = 0; // Null terminate buffer.
58 if (X == 0) {
59 *--BufPtr = '0'; // Handle special case.
60 return BufPtr;
61 }
46 static inline std::string utohexstr(uint64_t X, bool LowerCase = false) {
47 char Buffer[17];
48 char *BufPtr = std::end(Buffer);
49
50 if (X == 0) *--BufPtr = '0';
6251
6352 while (X) {
6453 unsigned char Mod = static_cast(X) & 15;
6554 *--BufPtr = hexdigit(Mod, LowerCase);
6655 X >>= 4;
6756 }
68 return BufPtr;
69 }
7057
71 static inline std::string utohexstr(uint64_t X, bool LowerCase = false) {
72 char Buffer[17];
73 return utohex_buffer(X, std::end(Buffer), LowerCase);
58 return std::string(BufPtr, std::end(Buffer));
7459 }
7560
7661 static inline std::string utostr_32(uint32_t X, bool isNeg = false) {