aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2023-08-25 16:09:55 +0200
committerGitHub <noreply@github.com>2023-08-25 14:09:55 +0000
commit585a25a21278704ced0265b9e38e750bee523b54 (patch)
treeaa9e37a8c87ded19f8f6c6e56f8c2aab01b04932 /components/script
parent9c310b6d4ed2d0424cafeaf8e012d2bc537a8e4b (diff)
downloadservo-585a25a21278704ced0265b9e38e750bee523b54.tar.gz
servo-585a25a21278704ced0265b9e38e750bee523b54.zip
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.
Diffstat (limited to 'components/script')
-rw-r--r--components/script/Cargo.toml1
-rw-r--r--components/script/dom/bindings/root.rs7
-rw-r--r--components/script/lib.rs1
3 files changed, 4 insertions, 5 deletions
diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml
index 0a8b713ce9d..e4f84658730 100644
--- a/components/script/Cargo.toml
+++ b/components/script/Cargo.toml
@@ -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 }
diff --git a/components/script/dom/bindings/root.rs b/components/script/dom/bindings/root.rs
index b0b7eeb146d..b51730848b6 100644
--- a/components/script/dom/bindings/root.rs
+++ b/components/script/dom/bindings/root.rs
@@ -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);
}
}
diff --git a/components/script/lib.rs b/components/script/lib.rs
index 3d46f4f797c..ecb4bf8a853 100644
--- a/components/script/lib.rs
+++ b/components/script/lib.rs
@@ -4,6 +4,7 @@
#![feature(core_intrinsics)]
#![feature(drain_filter)]
+#![feature(once_cell)]
#![feature(plugin)]
#![feature(register_tool)]
#![deny(unsafe_code)]