@@ -60,53 +60,51 @@ namespace swift {
60
60
class Fingerprint final {
61
61
public:
62
62
// / 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.
66
63
constexpr static size_t DIGEST_LENGTH = 32 ;
67
64
65
+ using Core = std::pair<uint64_t , uint64_t >;
68
66
private:
69
- std::string Core;
67
+ Core core ;
70
68
71
69
public:
70
+ // / Creates a fingerprint value from a pair of 64-bit integers.
71
+ explicit Fingerprint (Fingerprint::Core value) : core(value) {}
72
+
72
73
// / Creates a fingerprint value from the given input string that is known to
73
74
// / be a 32-byte hash value.
74
75
// /
75
76
// / In +asserts builds, strings that violate this invariant will crash. If a
76
77
// / fingerprint value is needed to represent an "invalid" state, use a
77
78
// / 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);
82
80
83
81
// / Creates a fingerprint value from the given input string literal.
84
82
template <std::size_t N>
85
83
explicit Fingerprint (const char (&literal)[N])
86
- : Core{ literal, N-1 } {
84
+ : Fingerprint{ Fingerprint::fromString ({ literal, N-1 }). core } {
87
85
static_assert (N == Fingerprint::DIGEST_LENGTH + 1 ,
88
86
" String literal must be 32 bytes in length!" );
89
87
}
90
88
91
89
// / Creates a fingerprint value by consuming the given \c MD5Result from LLVM.
92
90
explicit Fingerprint (llvm::MD5::MD5Result &&MD5Value)
93
- : Core {MD5Value.digest (). str ()} {}
91
+ : core {MD5Value.words ()} {}
94
92
95
93
public:
96
94
// / Retrieve the raw underlying bytes of this fingerprint.
97
- llvm::StringRef getRawValue () const { return Core; }
95
+ llvm::SmallString<Fingerprint::DIGEST_LENGTH> getRawValue () const ;
98
96
99
97
public:
100
98
friend bool operator ==(const Fingerprint &lhs, const Fingerprint &rhs) {
101
- return lhs.Core == rhs.Core ;
99
+ return lhs.core == rhs.core ;
102
100
}
103
101
104
102
friend bool operator !=(const Fingerprint &lhs, const Fingerprint &rhs) {
105
- return lhs.Core != rhs.Core ;
103
+ return lhs.core != rhs.core ;
106
104
}
107
105
108
106
friend llvm::hash_code hash_value (const Fingerprint &fp) {
109
- return llvm::hash_value (fp.Core );
107
+ return llvm::hash_value (fp.core );
110
108
}
111
109
112
110
public:
@@ -115,7 +113,7 @@ class Fingerprint final {
115
113
// / This fingerprint is a perfectly fine value for an MD5 hash, but it is
116
114
// / completely arbitrary.
117
115
static Fingerprint ZERO () {
118
- return Fingerprint (" 00000000000000000000000000000000 " );
116
+ return Fingerprint (Fingerprint::Core{ 0 , 0 } );
119
117
}
120
118
121
119
private:
@@ -124,7 +122,7 @@ class Fingerprint final {
124
122
// /
125
123
// / Very well, LLVM. A default value you shall have.
126
124
friend class llvm ::yaml::IO;
127
- Fingerprint () : Core(DIGEST_LENGTH, ' 0 ' ) {}
125
+ Fingerprint () : core{Fingerprint:: Core{ 0 , 0 }} {}
128
126
};
129
127
130
128
void simple_display (llvm::raw_ostream &out, const Fingerprint &fp);
0 commit comments