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

View file

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

View file

@ -33,9 +33,8 @@ use crate::dom::node::Node;
use js::jsapi::{Heap, JSObject, JSTracer};
use js::rust::GCMethods;
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
use mitochondria::OnceCell;
use script_layout_interface::TrustedNodeAddress;
use std::cell::{Cell, UnsafeCell};
use std::cell::{Cell, OnceCell, UnsafeCell};
use std::default::Default;
use std::hash::{Hash, Hasher};
use std::marker::PhantomData;
@ -718,7 +717,7 @@ where
F: FnOnce() -> DomRoot<T>,
{
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)]
unsafe impl<T: DomObject> JSTraceable for DomOnceCell<T> {
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);
}
}

View file

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