Skip to content

Commit 06fe8b5

Browse files
committed
Refactor interning update list to not include the keys.
1 parent be65949 commit 06fe8b5

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

webrender/src/intern.rs

+22-16
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use internal_types::FastHashMap;
66
use std::fmt::Debug;
77
use std::hash::Hash;
88
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;
1211

1312
/*
1413
@@ -60,7 +59,9 @@ pub struct UpdateList<S> {
6059
/// The current epoch of the scene builder.
6160
epoch: Epoch,
6261
/// 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>,
6465
}
6566

6667
#[cfg_attr(feature = "capture", derive(Serialize))]
@@ -89,17 +90,17 @@ impl <T> Handle<T> where T: Copy {
8990

9091
#[cfg_attr(feature = "capture", derive(Serialize))]
9192
#[cfg_attr(feature = "replay", derive(Deserialize))]
92-
pub enum UpdateKind<S> {
93-
Insert(S),
93+
pub enum UpdateKind {
94+
Insert,
9495
Remove,
9596
UpdateEpoch,
9697
}
9798

9899
#[cfg_attr(feature = "capture", derive(Serialize))]
99100
#[cfg_attr(feature = "replay", derive(Deserialize))]
100-
pub struct Update<S> {
101+
pub struct Update {
101102
index: usize,
102-
kind: UpdateKind<S>,
103+
kind: UpdateKind,
103104
}
104105

105106
/// 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 {
137138
&mut self,
138139
update_list: UpdateList<S>,
139140
) {
141+
let mut data_iter = update_list.data.into_iter();
140142
for update in update_list.updates {
141143
match update.kind {
142-
UpdateKind::Insert(data) => {
144+
UpdateKind::Insert => {
145+
let data = data_iter.next().unwrap();
143146
let item = Item {
144147
data: T::from(data),
145148
epoch: update_list.epoch,
@@ -194,11 +197,11 @@ pub struct Interner<S : Eq + Hash + Clone + Debug, D, M> {
194197
/// List of free slots in the data store for re-use.
195198
free_list: Vec<usize>,
196199
/// 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>,
198203
/// The current epoch for the interner.
199204
current_epoch: Epoch,
200-
/// Incrementing counter for identifying stable values.
201-
next_uid: usize,
202205
/// The information associated with each interned
203206
/// item that can be accessed by the interner.
204207
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
211214
map: FastHashMap::default(),
212215
free_list: Vec::new(),
213216
updates: Vec::new(),
217+
update_data: Vec::new(),
214218
current_epoch: Epoch(1),
215-
next_uid: 0,
216219
local_data: Vec::new(),
217220
}
218221
}
@@ -259,15 +262,16 @@ impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + De
259262
// Add a pending update to insert the new data.
260263
self.updates.push(Update {
261264
index,
262-
kind: UpdateKind::Insert(data.clone()),
265+
kind: UpdateKind::Insert,
263266
});
267+
self.update_data.alloc().init(data.clone());
264268

265269
// Generate a handle for access via the data store.
266270
let handle = Handle {
267271
index: index as u32,
268272
epoch: self.current_epoch,
269273
uid: ItemUid {
270-
uid: self.next_uid,
274+
uid: self.map.len(),
271275
_marker: PhantomData,
272276
},
273277
_marker: PhantomData,
@@ -276,7 +280,6 @@ impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + De
276280
// Store this handle so the next time it is
277281
// interned, it gets re-used.
278282
self.map.insert(data.clone(), handle);
279-
self.next_uid += 1;
280283

281284
// Create the local data for this item that is
282285
// being interned.
@@ -298,6 +301,8 @@ impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + De
298301
/// a GC step that removes old entries.
299302
pub fn end_frame_and_get_pending_updates(&mut self) -> UpdateList<S> {
300303
let mut updates = mem::replace(&mut self.updates, Vec::new());
304+
let data = mem::replace(&mut self.update_data, Vec::new());
305+
301306
let free_list = &mut self.free_list;
302307
let current_epoch = self.current_epoch.0;
303308

@@ -327,6 +332,7 @@ impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + De
327332

328333
let updates = UpdateList {
329334
updates,
335+
data,
330336
epoch: self.current_epoch,
331337
};
332338

0 commit comments

Comments
 (0)