mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Remove most of the things in layout 2020
We keep mostly the query system. There is probably more to delete but that's a good start I think.
This commit is contained in:
parent
4846d76e82
commit
317d700f5d
47 changed files with 75 additions and 29854 deletions
|
@ -2,15 +2,9 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! Reference-counted pointers to flows.
|
||||
//!
|
||||
//! Eventually, with dynamically sized types in Rust, much of this code will
|
||||
//! be superfluous. This design is largely duplicating logic of Arc<T> and
|
||||
//! Weak<T>; please see comments there for details.
|
||||
|
||||
use crate::flow::Flow;
|
||||
use std::ops::Deref;
|
||||
use std::sync::{Arc, Weak};
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct FlowRef(Arc<dyn Flow>);
|
||||
|
@ -23,42 +17,14 @@ impl Deref for FlowRef {
|
|||
}
|
||||
|
||||
impl FlowRef {
|
||||
/// `FlowRef`s can only be made available to the traversal code.
|
||||
/// See https://github.com/servo/servo/issues/14014 for more details.
|
||||
pub fn new(mut r: Arc<dyn Flow>) -> Self {
|
||||
// This assertion checks that this `FlowRef` does not alias normal `Arc`s.
|
||||
// If that happens, we're in trouble.
|
||||
assert!(Arc::get_mut(&mut r).is_some());
|
||||
FlowRef(r)
|
||||
}
|
||||
pub fn get_mut(this: &mut FlowRef) -> Option<&mut dyn Flow> {
|
||||
Arc::get_mut(&mut this.0)
|
||||
}
|
||||
pub fn downgrade(this: &FlowRef) -> WeakFlowRef {
|
||||
WeakFlowRef(Arc::downgrade(&this.0))
|
||||
}
|
||||
pub fn into_arc(mut this: FlowRef) -> Arc<dyn Flow> {
|
||||
// This assertion checks that this `FlowRef` does not alias normal `Arc`s.
|
||||
// If that happens, we're in trouble.
|
||||
assert!(FlowRef::get_mut(&mut this).is_some());
|
||||
this.0
|
||||
}
|
||||
/// WARNING: This should only be used when there is no aliasing:
|
||||
/// when the traversal ensures that no other threads accesses the same flow at the same time.
|
||||
/// See https://github.com/servo/servo/issues/6503
|
||||
/// Use Arc::get_mut instead when possible (e.g. on an Arc that was just created).
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub fn deref_mut(this: &mut FlowRef) -> &mut dyn Flow {
|
||||
let ptr: *const dyn Flow = &*this.0;
|
||||
unsafe { &mut *(ptr as *mut dyn Flow) }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct WeakFlowRef(Weak<dyn Flow>);
|
||||
|
||||
impl WeakFlowRef {
|
||||
pub fn upgrade(&self) -> Option<FlowRef> {
|
||||
self.0.upgrade().map(FlowRef)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue