Skip to content

Commit b4f7e43

Browse files
author
bors-servo
authored
Auto merge of #3341 - jrmuizel:empty-item, r=gw3583
Improve code quality for push_new_empty_item. LLVM's ability to eliminate memcpy's across basic blocks is bad. Because of this, we want to make sure that we avoid putting branches in code where we want the memcpy elimination to happen. rust-lang/rust#56172 has a reduced test case of this happening. This change lifts the branch caused by unwrap() above the creation of the SpecificDisplayItem. It ends up saving a memcpy of 127 bytes along with reducing pop_reference_frame by 18 instructions. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/3341) <!-- Reviewable:end -->
2 parents 9a903a2 + 97a7db1 commit b4f7e43

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

webrender_api/src/display_list.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -1002,13 +1002,13 @@ impl DisplayListBuilder {
10021002
)
10031003
}
10041004

1005-
fn push_new_empty_item(&mut self, item: SpecificDisplayItem) {
1005+
fn push_new_empty_item(&mut self, item: SpecificDisplayItem, clip_and_scroll: &ClipAndScrollInfo) {
10061006
let info = LayoutPrimitiveInfo::new(LayoutRect::zero());
10071007
serialize_fast(
10081008
&mut self.data,
10091009
&DisplayItem {
10101010
item,
1011-
clip_and_scroll: *self.clip_stack.last().unwrap(),
1011+
clip_and_scroll: *clip_and_scroll,
10121012
info,
10131013
}
10141014
)
@@ -1279,7 +1279,8 @@ impl DisplayListBuilder {
12791279
}
12801280

12811281
pub fn pop_reference_frame(&mut self) {
1282-
self.push_new_empty_item(SpecificDisplayItem::PopReferenceFrame);
1282+
let clip_and_scroll = *self.clip_stack.last().unwrap();
1283+
self.push_new_empty_item(SpecificDisplayItem::PopReferenceFrame, &clip_and_scroll);
12831284
}
12841285

12851286
pub fn push_stacking_context(
@@ -1305,14 +1306,16 @@ impl DisplayListBuilder {
13051306
}
13061307

13071308
pub fn pop_stacking_context(&mut self) {
1308-
self.push_new_empty_item(SpecificDisplayItem::PopStackingContext);
1309+
let clip_and_scroll = *self.clip_stack.last().unwrap();
1310+
self.push_new_empty_item(SpecificDisplayItem::PopStackingContext, &clip_and_scroll);
13091311
}
13101312

13111313
pub fn push_stops(&mut self, stops: &[GradientStop]) {
13121314
if stops.is_empty() {
13131315
return;
13141316
}
1315-
self.push_new_empty_item(SpecificDisplayItem::SetGradientStops);
1317+
let clip_and_scroll = *self.clip_stack.last().unwrap();
1318+
self.push_new_empty_item(SpecificDisplayItem::SetGradientStops, &clip_and_scroll);
13161319
self.push_iter(stops);
13171320
}
13181321

@@ -1399,7 +1402,8 @@ impl DisplayListBuilder {
13991402
I::IntoIter: ExactSizeIterator + Clone,
14001403
{
14011404
let id = self.generate_clip_chain_id();
1402-
self.push_new_empty_item(SpecificDisplayItem::ClipChain(ClipChainItem { id, parent }));
1405+
let clip_and_scroll = *self.clip_stack.last().unwrap();
1406+
self.push_new_empty_item(SpecificDisplayItem::ClipChain(ClipChainItem { id, parent }), &clip_and_scroll);
14031407
self.push_iter(clips);
14041408
id
14051409
}
@@ -1524,7 +1528,8 @@ impl DisplayListBuilder {
15241528
}
15251529

15261530
pub fn pop_all_shadows(&mut self) {
1527-
self.push_new_empty_item(SpecificDisplayItem::PopAllShadows);
1531+
let clip_and_scroll = *self.clip_stack.last().unwrap();
1532+
self.push_new_empty_item(SpecificDisplayItem::PopAllShadows, &clip_and_scroll);
15281533
}
15291534

15301535
pub fn finalize(self) -> (PipelineId, LayoutSize, BuiltDisplayList) {

0 commit comments

Comments
 (0)