From a90a5cba08fdf6c0ceb95101c275108a152a3aed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:35:37 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- servo/components/style/bloom.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'servo/components/style/bloom.rs') diff --git a/servo/components/style/bloom.rs b/servo/components/style/bloom.rs index 63be881505..a5f47d8b41 100644 --- a/servo/components/style/bloom.rs +++ b/servo/components/style/bloom.rs @@ -10,11 +10,8 @@ use crate::dom::{SendElement, TElement}; use crate::LocalName; use atomic_refcell::{AtomicRefCell, AtomicRefMut}; -use owning_ref::OwningHandle; use selectors::bloom::BloomFilter; -use servo_arc::Arc; use smallvec::SmallVec; -use std::mem::ManuallyDrop; thread_local! { /// Bloom filters are large allocations, so we store them in thread-local storage @@ -24,10 +21,12 @@ thread_local! { /// We intentionally leak this from TLS because we don't have the guarantee /// of TLS destructors to run in worker threads. /// + /// Also, leaking it guarantees that we can borrow it indefinitely. + /// /// We could change this once https://github.com/rayon-rs/rayon/issues/688 - /// is fixed, hopefully. - static BLOOM_KEY: ManuallyDrop>> = - ManuallyDrop::new(Arc::new_leaked(Default::default())); + /// is fixed, hopefully, which point we'd need to change the filter member below to be an + /// arc and carry an owning reference around or so. + static BLOOM_KEY: &'static AtomicRefCell = Box::leak(Default::default()); } /// A struct that allows us to fast-reject deep descendant selectors avoiding @@ -66,7 +65,7 @@ pub struct StyleBloom { /// was created. We use AtomicRefCell so that this is all |Send|, which allows /// StyleBloom to live in ThreadLocalStyleContext, which is dropped from the /// parent thread. - filter: OwningHandle>, AtomicRefMut<'static, BloomFilter>>, + filter: AtomicRefMut<'static, BloomFilter>, /// The stack of elements that this bloom filter contains, along with the /// number of hashes pushed for each element. @@ -152,9 +151,7 @@ impl StyleBloom { // See https://github.com/servo/servo/pull/18420#issuecomment-328769322 #[inline(never)] pub fn new() -> Self { - let bloom_arc = BLOOM_KEY.with(|b| Arc::clone(&*b)); - let filter = - OwningHandle::new_with_fn(bloom_arc, |x| unsafe { x.as_ref() }.unwrap().borrow_mut()); + let filter = BLOOM_KEY.with(|b| b.borrow_mut()); debug_assert!( filter.is_zeroed(), "Forgot to zero the bloom filter last time" -- cgit v1.2.3