Skip to content

Commit f89a040

Browse files
committed
Bug 1511661 - Update webrender to commit 1619d945e853db14a9d62ed75dce7216ff3cdbc2 (WR PR #3366). r=kats
servo/webrender#3366 Differential Revision: https://phabricator.services.mozilla.com/D13627 UltraBlame original commit: df8c8aa616045a2076d1f0c8b1ebedf322aec212
1 parent 519cb16 commit f89a040

File tree

3 files changed

+58
-28
lines changed

3 files changed

+58
-28
lines changed

gfx/webrender_bindings/revision.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dbaa10971f08f964120ba339f5b0ab3e7ace77d6
1+
1619d945e853db14a9d62ed75dce7216ff3cdbc2

gfx/wr/webrender/src/intern.rs

Lines changed: 26 additions & 26 deletions
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

6160
epoch: Epoch,
6261

63-
updates: Vec<Update<S>>,
62+
updates: Vec<Update>,
63+
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

@@ -137,18 +138,14 @@ 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) => {
143-
let item = Item {
144-
data: T::from(data),
144+
UpdateKind::Insert => {
145+
self.items.entry(update.index).set(Item {
146+
data: T::from(data_iter.next().unwrap()),
145147
epoch: update_list.epoch,
146-
};
147-
if self.items.len() == update.index {
148-
self.items.push(item)
149-
} else {
150-
self.items[update.index] = item;
151-
}
148+
});
152149
}
153150
UpdateKind::Remove => {
154151
self.items[update.index].epoch = Epoch::INVALID;
@@ -158,6 +155,7 @@ impl<S, T, M> DataStore<S, T, M> where S: Debug, T: From<S>, M: Debug {
158155
}
159156
}
160157
}
158+
debug_assert!(data_iter.next().is_none());
161159
}
162160
}
163161

@@ -194,7 +192,9 @@ pub struct Interner<S : Eq + Hash + Clone + Debug, D, M> {
194192

195193
free_list: Vec<usize>,
196194

197-
updates: Vec<Update<S>>,
195+
updates: Vec<Update>,
196+
197+
update_data: Vec<S>,
198198

199199
current_epoch: Epoch,
200200

@@ -211,6 +211,7 @@ impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + De
211211
map: FastHashMap::default(),
212212
free_list: Vec::new(),
213213
updates: Vec::new(),
214+
update_data: Vec::new(),
214215
current_epoch: Epoch(1),
215216
next_uid: 0,
216217
local_data: Vec::new(),
@@ -259,8 +260,9 @@ impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + De
259260

260261
self.updates.push(Update {
261262
index,
262-
kind: UpdateKind::Insert(data.clone()),
263+
kind: UpdateKind::Insert,
263264
});
265+
self.update_data.alloc().init(data.clone());
264266

265267

266268
let handle = Handle {
@@ -280,15 +282,10 @@ impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + De
280282

281283

282284

283-
let local_item = Item {
285+
self.local_data.entry(index).set(Item {
284286
epoch: self.current_epoch,
285287
data: f(),
286-
};
287-
if self.local_data.len() == index {
288-
self.local_data.push(local_item);
289-
} else {
290-
self.local_data[index] = local_item;
291-
}
288+
});
292289

293290
handle
294291
}
@@ -298,6 +295,8 @@ impl<S, D, M> Interner<S, D, M> where S: Eq + Hash + Clone + Debug, M: Copy + De
298295

299296
pub fn end_frame_and_get_pending_updates(&mut self) -> UpdateList<S> {
300297
let mut updates = mem::replace(&mut self.updates, Vec::new());
298+
let data = mem::replace(&mut self.update_data, Vec::new());
299+
301300
let free_list = &mut self.free_list;
302301
let current_epoch = self.current_epoch.0;
303302

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

328327
let updates = UpdateList {
329328
updates,
329+
data,
330330
epoch: self.current_epoch,
331331
};
332332

gfx/wr/webrender/src/util.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const NEARLY_ZERO: f32 = 1.0 / 4096.0;
1717

1818

1919

20-
#[must_use]
2120
pub struct Allocation<'a, T: 'a> {
2221
vec: &'a mut Vec<T>,
2322
index: usize,
@@ -37,8 +36,28 @@ impl<'a, T> Allocation<'a, T> {
3736
}
3837
}
3938

39+
40+
pub enum VecEntry<'a, T: 'a> {
41+
Vacant(Allocation<'a, T>),
42+
Occupied(&'a mut T),
43+
}
44+
45+
impl<'a, T> VecEntry<'a, T> {
46+
#[inline(always)]
47+
pub fn set(self, value: T) {
48+
match self {
49+
VecEntry::Vacant(alloc) => { alloc.init(value); }
50+
VecEntry::Occupied(slot) => { *slot = value; }
51+
}
52+
}
53+
}
54+
4055
pub trait VecHelper<T> {
56+
4157
fn alloc(&mut self) -> Allocation<T>;
58+
59+
60+
fn entry(&mut self, index: usize) -> VecEntry<T>;
4261
}
4362

4463
impl<T> VecHelper<T> for Vec<T> {
@@ -52,6 +71,17 @@ impl<T> VecHelper<T> for Vec<T> {
5271
index,
5372
}
5473
}
74+
75+
fn entry(&mut self, index: usize) -> VecEntry<T> {
76+
if index < self.len() {
77+
VecEntry::Occupied(unsafe {
78+
self.get_unchecked_mut(index)
79+
})
80+
} else {
81+
assert_eq!(index, self.len());
82+
VecEntry::Vacant(self.alloc())
83+
}
84+
}
5585
}
5686

5787

0 commit comments

Comments
 (0)