Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -354,13 +354,9 @@ if (!MemBuffer) return None; - llvm::MD5 Hash; - llvm::MD5::MD5Result Result; - - Hash.update(MemBuffer->getBuffer()); - Hash.final(Result); - - Hash.stringifyResult(Result, Checksum); + llvm::toHex( + llvm::MD5::hash(llvm::arrayRefFromStringRef(MemBuffer->getBuffer())), + /*LowerCase*/ true, Checksum); return llvm::DIFile::CSK_MD5; } Index: llvm/include/llvm/ADT/StringExtras.h =================================================================== --- llvm/include/llvm/ADT/StringExtras.h +++ llvm/include/llvm/ADT/StringExtras.h @@ -29,14 +29,15 @@ namespace llvm { -template class SmallVectorImpl; class raw_ostream; /// hexdigit - Return the hexadecimal character for the /// given number \p X (which should be less than 16). inline char hexdigit(unsigned X, bool LowerCase = false) { - const char HexChar = LowerCase ? 'a' : 'A'; - return X < 10 ? '0' + X : HexChar + X - 10; + assert(X <= 16); + static const char *const LUT = "0123456789ABCDEF"; + const uint8_t Offset = LowerCase ? 32 : 0; + return LUT[X] | Offset; } /// Given an array of c-style strings terminated by a null pointer, construct @@ -164,23 +165,26 @@ /// Convert buffer \p Input to its hexadecimal representation. /// The returned string is double the size of \p Input. -inline std::string toHex(StringRef Input, bool LowerCase = false) { - static const char *const LUT = "0123456789ABCDEF"; - const uint8_t Offset = LowerCase ? 32 : 0; - size_t Length = Input.size(); - - std::string Output; - Output.reserve(2 * Length); - for (size_t i = 0; i < Length; ++i) { - const unsigned char c = Input[i]; - Output.push_back(LUT[c >> 4] | Offset); - Output.push_back(LUT[c & 15] | Offset); +inline void toHex(ArrayRef Input, bool LowerCase, + SmallVectorImpl &Output) { + const size_t Length = Input.size(); + Output.resize_for_overwrite(Length * 2); + + for (size_t i = 0; i < Length; i++) { + const uint8_t c = Input[i]; + Output[i * 2 ] = hexdigit(c >> 4, LowerCase); + Output[i * 2 + 1] = hexdigit(c & 15, LowerCase); } - return Output; } inline std::string toHex(ArrayRef Input, bool LowerCase = false) { - return toHex(toStringRef(Input), LowerCase); + SmallString<16> Output; + toHex(Input, LowerCase, Output); + return std::string(Output); +} + +inline std::string toHex(StringRef Input, bool LowerCase = false) { + return toHex(arrayRefFromStringRef(Input), LowerCase); } /// Store the binary representation of the two provided values, \p MSB and Index: llvm/include/llvm/Support/MD5.h =================================================================== --- llvm/include/llvm/Support/MD5.h +++ llvm/include/llvm/Support/MD5.h @@ -88,7 +88,7 @@ /// Translates the bytes in \p Res to a hex string that is /// deposited into \p Str. The result will be of length 32. - static void stringifyResult(MD5Result &Result, SmallString<32> &Str); + static void stringifyResult(MD5Result &Result, SmallVectorImpl &Str); /// Computes the hash for a given bytes. static std::array hash(ArrayRef Data); Index: llvm/lib/Support/MD5.cpp =================================================================== --- llvm/lib/Support/MD5.cpp +++ llvm/lib/Support/MD5.cpp @@ -40,10 +40,9 @@ #include "llvm/Support/MD5.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Endian.h" -#include "llvm/Support/Format.h" -#include "llvm/Support/raw_ostream.h" #include #include #include @@ -281,14 +280,12 @@ SmallString<32> MD5::MD5Result::digest() const { SmallString<32> Str; - raw_svector_ostream Res(Str); - for (int i = 0; i < 16; ++i) - Res << format("%.2x", Bytes[i]); + toHex(Bytes, /*LowerCase*/ true, Str); return Str; } -void MD5::stringifyResult(MD5Result &Result, SmallString<32> &Str) { - Str = Result.digest(); +void MD5::stringifyResult(MD5Result &Result, SmallVectorImpl &Str) { + toHex(Result.Bytes, /*LowerCase*/ true, Str); } std::array MD5::hash(ArrayRef Data) {