Use std::cell::OnceCell and remove mitochondria dependency (#30207)

`OnceCell` is now part of the standard library and we'll be able to use
it once we upgrade rust. For now we can use the version that's shipped
behind a feature flag in rust. This removes a dependency on one crate.
This commit is contained in:
Martin Robinson 2023-08-25 16:09:55 +02:00 committed by GitHub
parent 9c310b6d4e
commit 585a25a212
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 11 additions and 21 deletions

8
Cargo.lock generated
View file

@ -3129,7 +3129,6 @@ dependencies = [
"lazy_static", "lazy_static",
"libc", "libc",
"log", "log",
"mitochondria",
"msg", "msg",
"net_traits", "net_traits",
"parking_lot", "parking_lot",
@ -3735,12 +3734,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "mitochondria"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9de3eca27871df31c33b807f834b94ef7d000956f57aa25c5aed9c5f0aae8f6f"
[[package]] [[package]]
name = "mozangle" name = "mozangle"
version = "0.3.5" version = "0.3.5"
@ -4991,7 +4984,6 @@ dependencies = [
"metrics", "metrics",
"mime", "mime",
"mime_guess", "mime_guess",
"mitochondria",
"mozangle", "mozangle",
"mozjs", "mozjs",
"msg", "msg",

View file

@ -49,7 +49,6 @@ log = "0.4"
malloc_size_of_derive = "0.1" malloc_size_of_derive = "0.1"
mime = "0.3.13" mime = "0.3.13"
mime_guess = "2.0.3" mime_guess = "2.0.3"
mitochondria = "1.1.2"
mozangle = "0.3" mozangle = "0.3"
num-traits = "0.2" num-traits = "0.2"
parking_lot = "0.12" parking_lot = "0.12"

View file

@ -28,7 +28,6 @@ html5ever = { workspace = true }
ipc-channel = { workspace = true } ipc-channel = { workspace = true }
libc = { workspace = true } libc = { workspace = true }
log = { workspace = true } log = { workspace = true }
mitochondria = { workspace = true }
msg = { path = "../msg" } msg = { path = "../msg" }
net_traits = { path = "../net_traits" } net_traits = { path = "../net_traits" }
parking_lot = { workspace = true } parking_lot = { workspace = true }

View file

@ -13,10 +13,10 @@ use embedder_traits::Cursor;
use euclid::{Point2D, SideOffsets2D, Size2D}; use euclid::{Point2D, SideOffsets2D, Size2D};
use fnv::FnvHashMap; use fnv::FnvHashMap;
use gfx::text::glyph::GlyphStore; use gfx::text::glyph::GlyphStore;
use mitochondria::OnceCell;
use msg::constellation_msg::BrowsingContextId; use msg::constellation_msg::BrowsingContextId;
use net_traits::image_cache::UsePlaceholder; use net_traits::image_cache::UsePlaceholder;
use script_traits::compositor::{CompositorDisplayListInfo, ScrollTreeNodeId}; use script_traits::compositor::{CompositorDisplayListInfo, ScrollTreeNodeId};
use std::cell::OnceCell;
use std::sync::Arc; use std::sync::Arc;
use style::computed_values::text_decoration_style::T as ComputedTextDecorationStyle; use style::computed_values::text_decoration_style::T as ComputedTextDecorationStyle;
use style::dom::OpaqueNode; use style::dom::OpaqueNode;
@ -440,7 +440,7 @@ impl<'a> BuilderForBoxFragment<'a> {
} }
fn content_rect(&self) -> &units::LayoutRect { fn content_rect(&self) -> &units::LayoutRect {
self.content_rect.init_once(|| { self.content_rect.get_or_init(|| {
self.fragment self.fragment
.content_rect .content_rect
.to_physical(self.fragment.style.writing_mode, self.containing_block) .to_physical(self.fragment.style.writing_mode, self.containing_block)
@ -450,7 +450,7 @@ impl<'a> BuilderForBoxFragment<'a> {
} }
fn padding_rect(&self) -> &units::LayoutRect { fn padding_rect(&self) -> &units::LayoutRect {
self.padding_rect.init_once(|| { self.padding_rect.get_or_init(|| {
self.fragment self.fragment
.padding_rect() .padding_rect()
.to_physical(self.fragment.style.writing_mode, self.containing_block) .to_physical(self.fragment.style.writing_mode, self.containing_block)
@ -462,11 +462,11 @@ impl<'a> BuilderForBoxFragment<'a> {
fn border_edge_clip(&self, builder: &mut DisplayListBuilder) -> Option<wr::ClipId> { fn border_edge_clip(&self, builder: &mut DisplayListBuilder) -> Option<wr::ClipId> {
*self *self
.border_edge_clip_id .border_edge_clip_id
.init_once(|| clip_for_radii(self.border_radius, self.border_rect, builder)) .get_or_init(|| clip_for_radii(self.border_radius, self.border_rect, builder))
} }
fn padding_edge_clip(&self, builder: &mut DisplayListBuilder) -> Option<wr::ClipId> { fn padding_edge_clip(&self, builder: &mut DisplayListBuilder) -> Option<wr::ClipId> {
*self.padding_edge_clip_id.init_once(|| { *self.padding_edge_clip_id.get_or_init(|| {
clip_for_radii( clip_for_radii(
inner_radii( inner_radii(
self.border_radius, self.border_radius,
@ -482,7 +482,7 @@ impl<'a> BuilderForBoxFragment<'a> {
} }
fn content_edge_clip(&self, builder: &mut DisplayListBuilder) -> Option<wr::ClipId> { fn content_edge_clip(&self, builder: &mut DisplayListBuilder) -> Option<wr::ClipId> {
*self.content_edge_clip_id.init_once(|| { *self.content_edge_clip_id.get_or_init(|| {
clip_for_radii( clip_for_radii(
inner_radii( inner_radii(
self.border_radius, self.border_radius,

View file

@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#![deny(unsafe_code)] #![deny(unsafe_code)]
#![feature(once_cell)]
#[macro_use] #[macro_use]
extern crate log; extern crate log;

View file

@ -76,7 +76,6 @@ media = { path = "../media" }
metrics = { path = "../metrics" } metrics = { path = "../metrics" }
mime = { workspace = true } mime = { workspace = true }
mime_guess = { workspace = true } mime_guess = { workspace = true }
mitochondria = { workspace = true }
msg = { path = "../msg" } msg = { path = "../msg" }
net_traits = { path = "../net_traits" } net_traits = { path = "../net_traits" }
num-traits = { workspace = true } num-traits = { workspace = true }

View file

@ -33,9 +33,8 @@ use crate::dom::node::Node;
use js::jsapi::{Heap, JSObject, JSTracer}; use js::jsapi::{Heap, JSObject, JSTracer};
use js::rust::GCMethods; use js::rust::GCMethods;
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
use mitochondria::OnceCell;
use script_layout_interface::TrustedNodeAddress; use script_layout_interface::TrustedNodeAddress;
use std::cell::{Cell, UnsafeCell}; use std::cell::{Cell, OnceCell, UnsafeCell};
use std::default::Default; use std::default::Default;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use std::marker::PhantomData; use std::marker::PhantomData;
@ -718,7 +717,7 @@ where
F: FnOnce() -> DomRoot<T>, F: FnOnce() -> DomRoot<T>,
{ {
assert_in_script(); assert_in_script();
&self.ptr.init_once(|| Dom::from_ref(&cb())) &self.ptr.get_or_init(|| Dom::from_ref(&cb()))
} }
} }
@ -742,7 +741,7 @@ impl<T: DomObject> MallocSizeOf for DomOnceCell<T> {
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
unsafe impl<T: DomObject> JSTraceable for DomOnceCell<T> { unsafe impl<T: DomObject> JSTraceable for DomOnceCell<T> {
unsafe fn trace(&self, trc: *mut JSTracer) { unsafe fn trace(&self, trc: *mut JSTracer) {
if let Some(ptr) = self.ptr.as_ref() { if let Some(ptr) = self.ptr.get() {
ptr.trace(trc); ptr.trace(trc);
} }
} }

View file

@ -4,6 +4,7 @@
#![feature(core_intrinsics)] #![feature(core_intrinsics)]
#![feature(drain_filter)] #![feature(drain_filter)]
#![feature(once_cell)]
#![feature(plugin)] #![feature(plugin)]
#![feature(register_tool)] #![feature(register_tool)]
#![deny(unsafe_code)] #![deny(unsafe_code)]