@@ -97,31 +97,6 @@ class OnDiskHashMappedTrie {
9797 MutableArrayRef<char > Data;
9898 };
9999
100- private:
101- struct HintT {
102- explicit operator ValueProxy () const {
103- ValueProxy Value;
104- Value.Data = MutableArrayRef<char >(
105- const_cast <char *>(reinterpret_cast <const char *>(P)), I);
106- Value.Hash = ArrayRef<uint8_t >(nullptr , B);
107- return Value;
108- }
109-
110- explicit HintT (ConstValueProxy Value)
111- : P(Value.Data.data()), I(Value.Data.size()), B(Value.Hash.size()) {
112- // Spot-check that this really was a hint.
113- assert (Value.Data .size () <= UINT16_MAX);
114- assert (Value.Hash .size () <= UINT16_MAX);
115- assert (Value.Hash .data () == nullptr );
116- }
117-
118- HintT (const void *P, uint16_t I, uint16_t B) : P(P), I(I), B(B) {}
119-
120- const void *P = nullptr ;
121- uint16_t I = 0 ;
122- uint16_t B = 0 ;
123- };
124-
125100public:
126101 template <class ProxyT > class PointerImpl {
127102 public:
@@ -133,50 +108,34 @@ class OnDiskHashMappedTrie {
133108
134109 const ProxyT &operator *() const {
135110 assert (IsValue);
136- return ValueOrHint ;
111+ return Value ;
137112 }
138113 const ProxyT *operator ->() const {
139114 assert (IsValue);
140- return &ValueOrHint ;
115+ return &Value ;
141116 }
142117
143118 PointerImpl () = default ;
144119
145120 protected:
146121 PointerImpl (FileOffset Offset, ProxyT Value)
147- : PointerImpl(Value, Offset, /* IsHint=*/ false , /* IsValue=*/ true ) {}
148-
149- explicit PointerImpl (FileOffset Offset, HintT H)
150- : PointerImpl(ValueProxy(H), Offset, /* IsHint=*/ true,
151- /* IsValue=*/ false) {}
152-
153- PointerImpl (ProxyT ValueOrHint, FileOffset Offset, bool IsHint,
154- bool IsValue)
155- : ValueOrHint(ValueOrHint), OffsetLow32((uint64_t )Offset.get()),
156- OffsetHigh16 ((uint64_t )Offset.get() >> 32), IsHint(IsHint),
157- IsValue(IsValue) {
158- checkOffset (Offset);
122+ : PointerImpl(Value, Offset, /* IsValue=*/ true ) {}
123+
124+ PointerImpl (ProxyT Value, FileOffset Offset, bool IsValue)
125+ : Value(Value), OffsetLow32((uint64_t )Offset.get()),
126+ OffsetHigh16 ((uint64_t )Offset.get() >> 32), IsValue(IsValue) {
127+ if (IsValue)
128+ checkOffset (Offset);
159129 }
160130
161131 static void checkOffset (FileOffset Offset) {
162132 assert (Offset.get () > 0 );
163133 assert ((uint64_t )Offset.get () < (1LL << 48 ));
164134 }
165135
166- std::optional<HintT> getHint (const OnDiskHashMappedTrie &This) const {
167- if (!IsHint)
168- return std::nullopt ;
169- HintT H (ValueOrHint);
170- assert (H.P == &This && " Expected hint to be for This" );
171- if (H.P != &This)
172- return std::nullopt ;
173- return H;
174- }
175-
176- ProxyT ValueOrHint;
136+ ProxyT Value;
177137 uint32_t OffsetLow32 = 0 ;
178138 uint16_t OffsetHigh16 = 0 ;
179- bool IsHint = false ;
180139 bool IsValue = false ;
181140 };
182141
@@ -194,7 +153,7 @@ class OnDiskHashMappedTrie {
194153 class pointer : public PointerImpl <ValueProxy> {
195154 public:
196155 operator const_pointer () const {
197- return const_pointer (ValueOrHint , getOffset (), IsHint , IsValue);
156+ return const_pointer (Value , getOffset (), IsValue);
198157 }
199158
200159 pointer () = default ;
@@ -205,8 +164,6 @@ class OnDiskHashMappedTrie {
205164 };
206165
207166 pointer getMutablePointer (const_pointer CP) {
208- if (std::optional<HintT> H = CP.getHint (*this ))
209- return pointer (CP.getOffset (), *H);
210167 if (!CP)
211168 return pointer ();
212169 ValueProxy V{CP->Hash , MutableArrayRef (const_cast <char *>(CP->Data .data ()),
@@ -254,25 +211,17 @@ class OnDiskHashMappedTrie {
254211 // / The in-memory \a HashMappedTrie uses LazyAtomicPointer to synchronize
255212 // / simultaneous writes, but that seems dangerous to use in a memory-mapped
256213 // / file in case a process crashes in the busy state.
257- Expected<pointer> insertLazy (const_pointer Hint, ArrayRef<uint8_t > Hash,
258- LazyInsertOnConstructCB OnConstruct = nullptr ,
259- LazyInsertOnLeakCB OnLeak = nullptr );
260214 Expected<pointer> insertLazy (ArrayRef<uint8_t > Hash,
261215 LazyInsertOnConstructCB OnConstruct = nullptr ,
262- LazyInsertOnLeakCB OnLeak = nullptr ) {
263- return insertLazy (const_pointer (), Hash, OnConstruct, OnLeak);
264- }
216+ LazyInsertOnLeakCB OnLeak = nullptr );
265217
266- Expected<pointer> insert (const_pointer Hint, const ConstValueProxy &Value) {
267- return insertLazy (Hint, Value.Hash , [&](FileOffset, ValueProxy Allocated) {
218+ Expected<pointer> insert (const ConstValueProxy &Value) {
219+ return insertLazy (Value.Hash , [&](FileOffset, ValueProxy Allocated) {
268220 assert (Allocated.Hash == Value.Hash );
269221 assert (Allocated.Data .size () == Value.Data .size ());
270222 llvm::copy (Value.Data , Allocated.Data .begin ());
271223 });
272224 }
273- Expected<pointer> insert (const ConstValueProxy &Value) {
274- return insert (const_pointer (), Value);
275- }
276225
277226 size_t size () const ;
278227 size_t capacity () const ;
0 commit comments