@@ -6,9 +6,8 @@ use internal_types::FastHashMap;
6
6
use std:: fmt:: Debug ;
7
7
use std:: hash:: Hash ;
8
8
use std:: marker:: PhantomData ;
9
- use std:: mem;
10
- use std:: ops;
11
- use std:: u64;
9
+ use std:: { mem, ops, u64} ;
10
+ use util:: VecHelper ;
12
11
13
12
/*
14
13
@@ -60,7 +59,9 @@ pub struct UpdateList<S> {
60
59
/// The current epoch of the scene builder.
61
60
epoch : Epoch ,
62
61
/// The additions and removals to apply.
63
- updates : Vec < Update < S > > ,
62
+ updates : Vec < Update > ,
63
+ /// Actual new data to insert.
64
+ data : Vec < S > ,
64
65
}
65
66
66
67
#[ cfg_attr( feature = "capture" , derive( Serialize ) ) ]
@@ -89,17 +90,17 @@ impl <T> Handle<T> where T: Copy {
89
90
90
91
#[ cfg_attr( feature = "capture" , derive( Serialize ) ) ]
91
92
#[ cfg_attr( feature = "replay" , derive( Deserialize ) ) ]
92
- pub enum UpdateKind < S > {
93
- Insert ( S ) ,
93
+ pub enum UpdateKind {
94
+ Insert ,
94
95
Remove ,
95
96
UpdateEpoch ,
96
97
}
97
98
98
99
#[ cfg_attr( feature = "capture" , derive( Serialize ) ) ]
99
100
#[ cfg_attr( feature = "replay" , derive( Deserialize ) ) ]
100
- pub struct Update < S > {
101
+ pub struct Update {
101
102
index : usize ,
102
- kind : UpdateKind < S > ,
103
+ kind : UpdateKind ,
103
104
}
104
105
105
106
/// The data item is stored with an epoch, for validating
@@ -137,9 +138,11 @@ impl<S, T, M> DataStore<S, T, M> where S: Debug, T: From<S>, M: Debug {
137
138
& mut self ,
138
139
update_list : UpdateList < S > ,
139
140
) {
141
+ let mut data_iter = update_list. data . into_iter ( ) ;
140
142
for update in update_list. updates {
141
143
match update. kind {
142
- UpdateKind :: Insert ( data) => {
144
+ UpdateKind :: Insert => {
145
+ let data = data_iter. next ( ) . unwrap ( ) ;
143
146
let item = Item {
144
147
data : T :: from ( data) ,
145
148
epoch : update_list. epoch ,
@@ -194,11 +197,11 @@ pub struct Interner<S : Eq + Hash + Clone + Debug, D, M> {
194
197
/// List of free slots in the data store for re-use.
195
198
free_list : Vec < usize > ,
196
199
/// Pending list of updates that need to be applied.
197
- updates : Vec < Update < S > > ,
200
+ updates : Vec < Update > ,
201
+ /// Pending new data to insert.
202
+ update_data : Vec < S > ,
198
203
/// The current epoch for the interner.
199
204
current_epoch : Epoch ,
200
- /// Incrementing counter for identifying stable values.
201
- next_uid : usize ,
202
205
/// The information associated with each interned
203
206
/// item that can be accessed by the interner.
204
207
local_data : Vec < Item < D > > ,
@@ -211,8 +214,8 @@ impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + De
211
214
map : FastHashMap :: default ( ) ,
212
215
free_list : Vec :: new ( ) ,
213
216
updates : Vec :: new ( ) ,
217
+ update_data : Vec :: new ( ) ,
214
218
current_epoch : Epoch ( 1 ) ,
215
- next_uid : 0 ,
216
219
local_data : Vec :: new ( ) ,
217
220
}
218
221
}
@@ -259,15 +262,16 @@ impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + De
259
262
// Add a pending update to insert the new data.
260
263
self . updates . push ( Update {
261
264
index,
262
- kind : UpdateKind :: Insert ( data . clone ( ) ) ,
265
+ kind : UpdateKind :: Insert ,
263
266
} ) ;
267
+ self . update_data . alloc ( ) . init ( data. clone ( ) ) ;
264
268
265
269
// Generate a handle for access via the data store.
266
270
let handle = Handle {
267
271
index : index as u32 ,
268
272
epoch : self . current_epoch ,
269
273
uid : ItemUid {
270
- uid : self . next_uid ,
274
+ uid : self . map . len ( ) ,
271
275
_marker : PhantomData ,
272
276
} ,
273
277
_marker : PhantomData ,
@@ -276,7 +280,6 @@ impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + De
276
280
// Store this handle so the next time it is
277
281
// interned, it gets re-used.
278
282
self . map . insert ( data. clone ( ) , handle) ;
279
- self . next_uid += 1 ;
280
283
281
284
// Create the local data for this item that is
282
285
// being interned.
@@ -298,6 +301,8 @@ impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + De
298
301
/// a GC step that removes old entries.
299
302
pub fn end_frame_and_get_pending_updates ( & mut self ) -> UpdateList < S > {
300
303
let mut updates = mem:: replace ( & mut self . updates , Vec :: new ( ) ) ;
304
+ let data = mem:: replace ( & mut self . update_data , Vec :: new ( ) ) ;
305
+
301
306
let free_list = & mut self . free_list ;
302
307
let current_epoch = self . current_epoch . 0 ;
303
308
@@ -327,6 +332,7 @@ impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + De
327
332
328
333
let updates = UpdateList {
329
334
updates,
335
+ data,
330
336
epoch : self . current_epoch ,
331
337
} ;
332
338
0 commit comments