@@ -60,53 +60,51 @@ namespace swift {
6060class Fingerprint final {
6161public:
6262 // / The size (in bytes) of the raw value of all fingerprints.
63- // /
64- // / This constant's value is justified by a static assertion in the
65- // / corresponding cpp file.
6663 constexpr static size_t DIGEST_LENGTH = 32 ;
6764
65+ using Core = std::pair<uint64_t , uint64_t >;
6866private:
69- std::string Core;
67+ Core core ;
7068
7169public:
70+ // / Creates a fingerprint value from a pair of 64-bit integers.
71+ explicit Fingerprint (Fingerprint::Core value) : core(value) {}
72+
7273 // / Creates a fingerprint value from the given input string that is known to
7374 // / be a 32-byte hash value.
7475 // /
7576 // / In +asserts builds, strings that violate this invariant will crash. If a
7677 // / fingerprint value is needed to represent an "invalid" state, use a
7778 // / vocabulary type like \c Optional<Fingerprint> instead.
78- explicit Fingerprint (std::string value) : Core(std::move(value)) {
79- assert (Core.size () == Fingerprint::DIGEST_LENGTH &&
80- " Only supports 32-byte hash values!" );
81- }
79+ static Fingerprint fromString (llvm::StringRef value);
8280
8381 // / Creates a fingerprint value from the given input string literal.
8482 template <std::size_t N>
8583 explicit Fingerprint (const char (&literal)[N])
86- : Core{ literal, N-1 } {
84+ : Fingerprint{ Fingerprint::fromString ({ literal, N-1 }). core } {
8785 static_assert (N == Fingerprint::DIGEST_LENGTH + 1 ,
8886 " String literal must be 32 bytes in length!" );
8987 }
9088
9189 // / Creates a fingerprint value by consuming the given \c MD5Result from LLVM.
9290 explicit Fingerprint (llvm::MD5::MD5Result &&MD5Value)
93- : Core {MD5Value.digest (). str ()} {}
91+ : core {MD5Value.words ()} {}
9492
9593public:
9694 // / Retrieve the raw underlying bytes of this fingerprint.
97- llvm::StringRef getRawValue () const { return Core; }
95+ llvm::SmallString<Fingerprint::DIGEST_LENGTH> getRawValue () const ;
9896
9997public:
10098 friend bool operator ==(const Fingerprint &lhs, const Fingerprint &rhs) {
101- return lhs.Core == rhs.Core ;
99+ return lhs.core == rhs.core ;
102100 }
103101
104102 friend bool operator !=(const Fingerprint &lhs, const Fingerprint &rhs) {
105- return lhs.Core != rhs.Core ;
103+ return lhs.core != rhs.core ;
106104 }
107105
108106 friend llvm::hash_code hash_value (const Fingerprint &fp) {
109- return llvm::hash_value (fp.Core );
107+ return llvm::hash_value (fp.core );
110108 }
111109
112110public:
@@ -115,7 +113,7 @@ class Fingerprint final {
115113 // / This fingerprint is a perfectly fine value for an MD5 hash, but it is
116114 // / completely arbitrary.
117115 static Fingerprint ZERO () {
118- return Fingerprint (" 00000000000000000000000000000000 " );
116+ return Fingerprint (Fingerprint::Core{ 0 , 0 } );
119117 }
120118
121119private:
@@ -124,7 +122,7 @@ class Fingerprint final {
124122 // /
125123 // / Very well, LLVM. A default value you shall have.
126124 friend class llvm ::yaml::IO;
127- Fingerprint () : Core(DIGEST_LENGTH, ' 0 ' ) {}
125+ Fingerprint () : core{Fingerprint:: Core{ 0 , 0 }} {}
128126};
129127
130128void simple_display (llvm::raw_ostream &out, const Fingerprint &fp);
0 commit comments