mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Use OnceCell instead of Option
This commit is contained in:
parent
252877ac62
commit
d8ed710824
3 changed files with 23 additions and 21 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -2751,6 +2751,7 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"msg",
|
"msg",
|
||||||
"net_traits",
|
"net_traits",
|
||||||
|
"once_cell",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"range",
|
"range",
|
||||||
"rayon",
|
"rayon",
|
||||||
|
@ -3709,6 +3710,12 @@ dependencies = [
|
||||||
"objc",
|
"objc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "891f486f630e5c5a4916c7e16c4b24a53e78c860b646e9f8e005e4f16847bfed"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "opaque-debug"
|
name = "opaque-debug"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
|
|
|
@ -25,6 +25,7 @@ ipc-channel = "0.12"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
msg = {path = "../msg"}
|
msg = {path = "../msg"}
|
||||||
net_traits = {path = "../net_traits"}
|
net_traits = {path = "../net_traits"}
|
||||||
|
once_cell = "1.2.0"
|
||||||
parking_lot = "0.9"
|
parking_lot = "0.9"
|
||||||
range = {path = "../range"}
|
range = {path = "../range"}
|
||||||
rayon = "1"
|
rayon = "1"
|
||||||
|
|
|
@ -9,6 +9,7 @@ use embedder_traits::Cursor;
|
||||||
use euclid::{Point2D, SideOffsets2D, Size2D, Vector2D};
|
use euclid::{Point2D, SideOffsets2D, Size2D, Vector2D};
|
||||||
use gfx::text::glyph::GlyphStore;
|
use gfx::text::glyph::GlyphStore;
|
||||||
use net_traits::image_cache::UsePlaceholder;
|
use net_traits::image_cache::UsePlaceholder;
|
||||||
|
use once_cell::unsync::OnceCell;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use style::dom::OpaqueNode;
|
use style::dom::OpaqueNode;
|
||||||
use style::properties::ComputedValues;
|
use style::properties::ComputedValues;
|
||||||
|
@ -128,12 +129,9 @@ struct BuilderForBoxFragment<'a> {
|
||||||
fragment: &'a BoxFragment,
|
fragment: &'a BoxFragment,
|
||||||
containing_block: &'a Rect<Length>,
|
containing_block: &'a Rect<Length>,
|
||||||
border_rect: units::LayoutRect,
|
border_rect: units::LayoutRect,
|
||||||
padding_rect: Option<units::LayoutRect>,
|
padding_rect: OnceCell<units::LayoutRect>,
|
||||||
border_radius: wr::BorderRadius,
|
border_radius: wr::BorderRadius,
|
||||||
|
border_edge_clip_id: OnceCell<Option<wr::ClipId>>,
|
||||||
// Outer `Option` is `None`: not initialized yet
|
|
||||||
// Inner `Option` is `None`: no border radius, no need to clip
|
|
||||||
border_edge_clip_id: Option<Option<wr::ClipId>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> BuilderForBoxFragment<'a> {
|
impl<'a> BuilderForBoxFragment<'a> {
|
||||||
|
@ -168,19 +166,17 @@ impl<'a> BuilderForBoxFragment<'a> {
|
||||||
containing_block,
|
containing_block,
|
||||||
border_rect,
|
border_rect,
|
||||||
border_radius,
|
border_radius,
|
||||||
padding_rect: None,
|
padding_rect: OnceCell::new(),
|
||||||
border_edge_clip_id: None,
|
border_edge_clip_id: OnceCell::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn padding_rect(&mut self) -> &units::LayoutRect {
|
fn padding_rect(&self) -> &units::LayoutRect {
|
||||||
let fragment = &self.fragment;
|
self.padding_rect.get_or_init(|| {
|
||||||
let containing_block = &self.containing_block;
|
self.fragment
|
||||||
self.padding_rect.get_or_insert_with(|| {
|
|
||||||
fragment
|
|
||||||
.padding_rect()
|
.padding_rect()
|
||||||
.to_physical(fragment.style.writing_mode, containing_block)
|
.to_physical(self.fragment.style.writing_mode, self.containing_block)
|
||||||
.translate(&containing_block.top_left)
|
.translate(&self.containing_block.top_left)
|
||||||
.into()
|
.into()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -190,18 +186,16 @@ impl<'a> BuilderForBoxFragment<'a> {
|
||||||
builder: &mut DisplayListBuilder,
|
builder: &mut DisplayListBuilder,
|
||||||
common: &mut wr::CommonItemProperties,
|
common: &mut wr::CommonItemProperties,
|
||||||
) {
|
) {
|
||||||
let border_radius = &self.border_radius;
|
let initialized = self.border_edge_clip_id.get_or_init(|| {
|
||||||
let border_rect = &self.border_rect;
|
if self.border_radius.is_zero() {
|
||||||
let initialized = self.border_edge_clip_id.get_or_insert_with(|| {
|
|
||||||
if border_radius.is_zero() {
|
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(builder.wr.define_clip(
|
Some(builder.wr.define_clip(
|
||||||
&builder.current_space_and_clip,
|
&builder.current_space_and_clip,
|
||||||
*border_rect,
|
self.border_rect,
|
||||||
Some(wr::ComplexClipRegion {
|
Some(wr::ComplexClipRegion {
|
||||||
rect: *border_rect,
|
rect: self.border_rect,
|
||||||
radii: *border_radius,
|
radii: self.border_radius,
|
||||||
mode: wr::ClipMode::Clip,
|
mode: wr::ClipMode::Clip,
|
||||||
}),
|
}),
|
||||||
None,
|
None,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue