@@ -97,31 +97,6 @@ class OnDiskHashMappedTrie {
97
97
MutableArrayRef<char > Data;
98
98
};
99
99
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
-
125
100
public:
126
101
template <class ProxyT > class PointerImpl {
127
102
public:
@@ -133,50 +108,34 @@ class OnDiskHashMappedTrie {
133
108
134
109
const ProxyT &operator *() const {
135
110
assert (IsValue);
136
- return ValueOrHint ;
111
+ return Value ;
137
112
}
138
113
const ProxyT *operator ->() const {
139
114
assert (IsValue);
140
- return &ValueOrHint ;
115
+ return &Value ;
141
116
}
142
117
143
118
PointerImpl () = default ;
144
119
145
120
protected:
146
121
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);
159
129
}
160
130
161
131
static void checkOffset (FileOffset Offset) {
162
132
assert (Offset.get () > 0 );
163
133
assert ((uint64_t )Offset.get () < (1LL << 48 ));
164
134
}
165
135
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;
177
137
uint32_t OffsetLow32 = 0 ;
178
138
uint16_t OffsetHigh16 = 0 ;
179
- bool IsHint = false ;
180
139
bool IsValue = false ;
181
140
};
182
141
@@ -194,7 +153,7 @@ class OnDiskHashMappedTrie {
194
153
class pointer : public PointerImpl <ValueProxy> {
195
154
public:
196
155
operator const_pointer () const {
197
- return const_pointer (ValueOrHint , getOffset (), IsHint , IsValue);
156
+ return const_pointer (Value , getOffset (), IsValue);
198
157
}
199
158
200
159
pointer () = default ;
@@ -205,8 +164,6 @@ class OnDiskHashMappedTrie {
205
164
};
206
165
207
166
pointer getMutablePointer (const_pointer CP) {
208
- if (std::optional<HintT> H = CP.getHint (*this ))
209
- return pointer (CP.getOffset (), *H);
210
167
if (!CP)
211
168
return pointer ();
212
169
ValueProxy V{CP->Hash , MutableArrayRef (const_cast <char *>(CP->Data .data ()),
@@ -254,25 +211,17 @@ class OnDiskHashMappedTrie {
254
211
// / The in-memory \a HashMappedTrie uses LazyAtomicPointer to synchronize
255
212
// / simultaneous writes, but that seems dangerous to use in a memory-mapped
256
213
// / 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 );
260
214
Expected<pointer> insertLazy (ArrayRef<uint8_t > Hash,
261
215
LazyInsertOnConstructCB OnConstruct = nullptr ,
262
- LazyInsertOnLeakCB OnLeak = nullptr ) {
263
- return insertLazy (const_pointer (), Hash, OnConstruct, OnLeak);
264
- }
216
+ LazyInsertOnLeakCB OnLeak = nullptr );
265
217
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) {
268
220
assert (Allocated.Hash == Value.Hash );
269
221
assert (Allocated.Data .size () == Value.Data .size ());
270
222
llvm::copy (Value.Data , Allocated.Data .begin ());
271
223
});
272
224
}
273
- Expected<pointer> insert (const ConstValueProxy &Value) {
274
- return insert (const_pointer (), Value);
275
- }
276
225
277
226
size_t size () const ;
278
227
size_t capacity () const ;
0 commit comments