diff options
author | Craig Topper <craig.topper@gmail.com> | 2016-01-31 20:00:22 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@gmail.com> | 2016-01-31 20:00:22 +0000 |
commit | fa8b2317a6a46fd7ca015fb56119aed3be37656a (patch) | |
tree | 11a21d54d70db5d7f2fd7ffc9c8c3daed7292648 | |
parent | 0069f56e331fbb954564c22935656c41056ce9c3 (diff) | |
download | bcm5719-llvm-fa8b2317a6a46fd7ca015fb56119aed3be37656a.tar.gz bcm5719-llvm-fa8b2317a6a46fd7ca015fb56119aed3be37656a.zip |
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
llvm-svn: 259329
-rw-r--r-- | llvm/include/llvm/ADT/StringExtras.h | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/llvm/include/llvm/ADT/StringExtras.h b/llvm/include/llvm/ADT/StringExtras.h index 2366e67f2d7..519c6073ae0 100644 --- a/llvm/include/llvm/ADT/StringExtras.h +++ b/llvm/include/llvm/ADT/StringExtras.h @@ -44,34 +44,19 @@ static inline unsigned hexDigitValue(char C) { return -1U; } -/// utohex_buffer - Emit the specified number into the buffer specified by -/// BufferEnd, returning a pointer to the start of the string. This can be used -/// like this: (note that the buffer must be large enough to handle any number): -/// char Buffer[40]; -/// printf("0x%s", utohex_buffer(X, Buffer+40)); -/// -/// This should only be used with unsigned types. -/// -template<typename IntTy> -static inline char *utohex_buffer(IntTy X, char *BufferEnd, bool LowerCase = false) { - char *BufPtr = BufferEnd; - *--BufPtr = 0; // Null terminate buffer. - if (X == 0) { - *--BufPtr = '0'; // Handle special case. - return BufPtr; - } +static inline std::string utohexstr(uint64_t X, bool LowerCase = false) { + char Buffer[17]; + char *BufPtr = std::end(Buffer); + + if (X == 0) *--BufPtr = '0'; while (X) { unsigned char Mod = static_cast<unsigned char>(X) & 15; *--BufPtr = hexdigit(Mod, LowerCase); X >>= 4; } - return BufPtr; -} -static inline std::string utohexstr(uint64_t X, bool LowerCase = false) { - char Buffer[17]; - return utohex_buffer(X, std::end(Buffer), LowerCase); + return std::string(BufPtr, std::end(Buffer)); } static inline std::string utostr_32(uint32_t X, bool isNeg = false) { |