hans updated this revision to Diff 398704.
hans added a comment.
(avoid toStringRef -> arrayRefFromStringRef by reshuffling the toHex overloads)
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D116960/new/
https://reviews.llvm.org/D116960
Files:
clang/lib/CodeGen/CGDebugInfo.cpp
llvm/include/llvm/ADT/StringExtras.h
llvm/include/llvm/Support/MD5.h
llvm/lib/Support/MD5.cpp
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 <array>
#include <cstdint>
#include <cstring>
@@ -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<char> &Str) {
+ toHex(Result.Bytes, /*LowerCase*/ true, Str);
}
std::array<uint8_t, 16> MD5::hash(ArrayRef<uint8_t> Data) {
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<char> &Str);
/// Computes the hash for a given bytes.
static std::array<uint8_t, 16> hash(ArrayRef<uint8_t> Data);
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<typename T> 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<uint8_t> Input, bool LowerCase,
+ SmallVectorImpl<char> &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<uint8_t> 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: 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;
}
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits