From fa8b2317a6a46fd7ca015fb56119aed3be37656a Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sun, 31 Jan 2016 20:00:22 +0000 Subject: [PATCH] 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 --- llvm/include/llvm/ADT/StringExtras.h | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/llvm/include/llvm/ADT/StringExtras.h b/llvm/include/llvm/ADT/StringExtras.h index 2366e67f2d7e..519c6073ae0d 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 -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(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) {