@@ -142,16 +142,10 @@ impl<S, T, M> DataStore<S, T, M> where S: Debug, T: From<S>, M: Debug {
142
142
for update in update_list. updates {
143
143
match update. kind {
144
144
UpdateKind :: Insert => {
145
- let data = data_iter. next ( ) . unwrap ( ) ;
146
- let item = Item {
147
- data : T :: from ( data) ,
145
+ self . items . entry ( update. index ) . set ( Item {
146
+ data : T :: from ( data_iter. next ( ) . unwrap ( ) ) ,
148
147
epoch : update_list. epoch ,
149
- } ;
150
- if self . items . len ( ) == update. index {
151
- self . items . push ( item)
152
- } else {
153
- self . items [ update. index ] = item;
154
- }
148
+ } ) ;
155
149
}
156
150
UpdateKind :: Remove => {
157
151
self . items [ update. index ] . epoch = Epoch :: INVALID ;
@@ -161,6 +155,7 @@ impl<S, T, M> DataStore<S, T, M> where S: Debug, T: From<S>, M: Debug {
161
155
}
162
156
}
163
157
}
158
+ debug_assert ! ( data_iter. next( ) . is_none( ) ) ;
164
159
}
165
160
}
166
161
@@ -202,6 +197,8 @@ pub struct Interner<S : Eq + Hash + Clone + Debug, D, M> {
202
197
update_data : Vec < S > ,
203
198
/// The current epoch for the interner.
204
199
current_epoch : Epoch ,
200
+ /// Incrementing counter for identifying stable values.
201
+ next_uid : usize ,
205
202
/// The information associated with each interned
206
203
/// item that can be accessed by the interner.
207
204
local_data : Vec < Item < D > > ,
@@ -216,6 +213,7 @@ impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + De
216
213
updates : Vec :: new ( ) ,
217
214
update_data : Vec :: new ( ) ,
218
215
current_epoch : Epoch ( 1 ) ,
216
+ next_uid : 0 ,
219
217
local_data : Vec :: new ( ) ,
220
218
}
221
219
}
@@ -271,7 +269,7 @@ impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + De
271
269
index : index as u32 ,
272
270
epoch : self . current_epoch ,
273
271
uid : ItemUid {
274
- uid : self . map . len ( ) ,
272
+ uid : self . next_uid ,
275
273
_marker : PhantomData ,
276
274
} ,
277
275
_marker : PhantomData ,
@@ -280,18 +278,14 @@ impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + De
280
278
// Store this handle so the next time it is
281
279
// interned, it gets re-used.
282
280
self . map . insert ( data. clone ( ) , handle) ;
281
+ self . next_uid += 1 ;
283
282
284
283
// Create the local data for this item that is
285
284
// being interned.
286
- let local_item = Item {
285
+ self . local_data . entry ( index ) . set ( Item {
287
286
epoch : self . current_epoch ,
288
287
data : f ( ) ,
289
- } ;
290
- if self . local_data . len ( ) == index {
291
- self . local_data . push ( local_item) ;
292
- } else {
293
- self . local_data [ index] = local_item;
294
- }
288
+ } ) ;
295
289
296
290
handle
297
291
}
0 commit comments