[llvm] r259329 - 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
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 31 12:00:22 PST 2016
Author: ctopper
Date: Sun Jan 31 14:00:22 2016
New Revision: 259329
URL: http://llvm.org/viewvc/llvm-project?rev=259329&view=rev
Log:
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
Modified:
llvm/trunk/include/llvm/ADT/StringExtras.h
Modified: llvm/trunk/include/llvm/ADT/StringExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringExtras.h?rev=259329&r1=259328&r2=259329&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringExtras.h (original)
+++ llvm/trunk/include/llvm/ADT/StringExtras.h Sun Jan 31 14:00:22 2016
@@ -44,34 +44,19 @@ static inline unsigned hexDigitValue(cha
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) {
More information about the llvm-commits
mailing list