mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-03 11:18:11 +08:00
Delete the dead OwnedContextImpl
This commit is contained in:
@@ -448,186 +448,12 @@ impl ExtractFootprint for () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==========================================
|
// ==============
|
||||||
// EXTRACT TRAIT IMPLS FOR `OwnedContextImpl`
|
// TYPE `Context`
|
||||||
// ==========================================
|
// ==============
|
||||||
|
|
||||||
impl ArcCtx for OwnedContextImpl {}
|
|
||||||
|
|
||||||
impl ExtractFootprint for OwnedContextImpl {
|
|
||||||
fn try_footprint(&self) -> Option<&Footprint> {
|
|
||||||
self.footprint.as_ref()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl ExtractRealTime for OwnedContextImpl {
|
|
||||||
fn try_real_time(&self) -> Option<f64> {
|
|
||||||
self.real_time
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl ExtractAnimationTime for OwnedContextImpl {
|
|
||||||
fn try_animation_time(&self) -> Option<f64> {
|
|
||||||
self.animation_time
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl ExtractPointerPosition for OwnedContextImpl {
|
|
||||||
fn try_pointer_position(&self) -> Option<DVec2> {
|
|
||||||
self.pointer_position
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl ExtractPosition for OwnedContextImpl {
|
|
||||||
fn try_position(&self) -> Option<impl Iterator<Item = DVec2>> {
|
|
||||||
self.position.clone().map(|x| x.into_iter())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl ExtractIndex for OwnedContextImpl {
|
|
||||||
fn try_index(&self) -> Option<impl Iterator<Item = usize>> {
|
|
||||||
self.index.clone().map(|x| x.into_iter())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
impl ExtractVarArgs for OwnedContextImpl {
|
|
||||||
fn vararg(&self, index: usize) -> Result<DynRef<'_>, VarArgsResult> {
|
|
||||||
let Some(ref inner) = self.varargs else {
|
|
||||||
let Some(ref parent) = self.parent else {
|
|
||||||
return Err(VarArgsResult::NoVarArgs);
|
|
||||||
};
|
|
||||||
return parent.vararg(index);
|
|
||||||
};
|
|
||||||
inner.get(index).map(|x| x.as_ref() as DynRef<'_>).ok_or(VarArgsResult::IndexOutOfBounds)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn varargs_len(&self) -> Result<usize, VarArgsResult> {
|
|
||||||
let Some(ref inner) = self.varargs else {
|
|
||||||
let Some(ref parent) = self.parent else {
|
|
||||||
return Err(VarArgsResult::NoVarArgs);
|
|
||||||
};
|
|
||||||
return parent.varargs_len();
|
|
||||||
};
|
|
||||||
Ok(inner.len())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn hash_varargs(&self, mut hasher: &mut dyn Hasher) {
|
|
||||||
match (&self.varargs, &self.parent) {
|
|
||||||
(Some(inner), _) => {
|
|
||||||
for arg in inner.iter() {
|
|
||||||
arg.hash(&mut hasher);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
(None, Some(parent)) => {
|
|
||||||
parent.hash_varargs(hasher);
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CloneVarArgs for Arc<OwnedContextImpl> {
|
|
||||||
fn arc_clone(&self) -> Option<Arc<dyn ExtractVarArgs + Send + Sync>> {
|
|
||||||
Some(self.clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ======================================
|
|
||||||
// TYPES `Context` AND `OwnedContextImpl`
|
|
||||||
// ======================================
|
|
||||||
|
|
||||||
pub type OwnedContext = Option<Arc<OwnedContextImpl>>;
|
|
||||||
pub type Context<'a> = ContextImpl<'a>;
|
pub type Context<'a> = ContextImpl<'a>;
|
||||||
type DynRef<'a> = &'a (dyn Any + Send + Sync);
|
type DynRef<'a> = &'a (dyn Any + Send + Sync);
|
||||||
type DynBox = Box<dyn AnyHash + Send + Sync>;
|
|
||||||
|
|
||||||
#[derive(dyn_any::DynAny)]
|
|
||||||
pub struct OwnedContextImpl {
|
|
||||||
parent: Option<Arc<dyn ExtractVarArgs + Sync + Send>>,
|
|
||||||
footprint: Option<Footprint>,
|
|
||||||
real_time: Option<f64>,
|
|
||||||
animation_time: Option<f64>,
|
|
||||||
pointer_position: Option<DVec2>,
|
|
||||||
position: Option<Vec<DVec2>>,
|
|
||||||
// This could be converted into a single enum to save extra bytes
|
|
||||||
index: Option<Vec<usize>>,
|
|
||||||
varargs: Option<Arc<[DynBox]>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Debug for OwnedContextImpl {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
f.debug_struct("OwnedContextImpl")
|
|
||||||
.field("parent", &self.parent.as_ref().map(|_| "<Parent>"))
|
|
||||||
.field("footprint", &self.footprint)
|
|
||||||
.field("real_time", &self.real_time)
|
|
||||||
.field("animation_time", &self.animation_time)
|
|
||||||
.field("pointer_position", &self.pointer_position)
|
|
||||||
.field("index", &self.index)
|
|
||||||
.field("varargs_len", &self.varargs.as_ref().map(|x| x.len()))
|
|
||||||
.finish()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for OwnedContextImpl {
|
|
||||||
#[track_caller]
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::empty()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl graphene_hash::CacheHash for OwnedContextImpl {
|
|
||||||
fn cache_hash<H: core::hash::Hasher>(&self, state: &mut H) {
|
|
||||||
self.footprint.cache_hash(state);
|
|
||||||
self.real_time.cache_hash(state);
|
|
||||||
self.animation_time.cache_hash(state);
|
|
||||||
self.pointer_position.cache_hash(state);
|
|
||||||
self.position.cache_hash(state);
|
|
||||||
self.index.cache_hash(state);
|
|
||||||
self.hash_varargs(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl OwnedContextImpl {
|
|
||||||
#[track_caller]
|
|
||||||
pub fn from<T: ExtractAll + CloneVarArgs>(value: T) -> Self {
|
|
||||||
OwnedContextImpl::from_flags(value, ContextFeatures::all())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[track_caller]
|
|
||||||
pub fn from_flags<T: ExtractAll + CloneVarArgs>(value: T, bitflags: ContextFeatures) -> Self {
|
|
||||||
let parent = bitflags
|
|
||||||
.contains(ContextFeatures::VARARGS)
|
|
||||||
.then(|| match value.varargs_len() {
|
|
||||||
Ok(x) if x > 0 => value.arc_clone(),
|
|
||||||
_ => None,
|
|
||||||
})
|
|
||||||
.flatten();
|
|
||||||
let footprint = bitflags.contains(ContextFeatures::FOOTPRINT).then(|| value.try_footprint().copied()).flatten();
|
|
||||||
let real_time = bitflags.contains(ContextFeatures::REAL_TIME).then(|| value.try_real_time()).flatten();
|
|
||||||
let animation_time = bitflags.contains(ContextFeatures::ANIMATION_TIME).then(|| value.try_animation_time()).flatten();
|
|
||||||
let pointer_position = bitflags.contains(ContextFeatures::POINTER_POSITION).then(|| value.try_pointer_position()).flatten();
|
|
||||||
let position = bitflags.contains(ContextFeatures::POSITION).then(|| value.try_position()).flatten().map(|x| x.collect());
|
|
||||||
let index = bitflags.contains(ContextFeatures::INDEX).then(|| value.try_index()).flatten().map(|x| x.collect());
|
|
||||||
|
|
||||||
OwnedContextImpl {
|
|
||||||
parent,
|
|
||||||
footprint,
|
|
||||||
real_time,
|
|
||||||
animation_time,
|
|
||||||
pointer_position,
|
|
||||||
position,
|
|
||||||
index,
|
|
||||||
varargs: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const fn empty() -> Self {
|
|
||||||
OwnedContextImpl {
|
|
||||||
parent: None,
|
|
||||||
footprint: None,
|
|
||||||
real_time: None,
|
|
||||||
animation_time: None,
|
|
||||||
pointer_position: None,
|
|
||||||
position: None,
|
|
||||||
index: None,
|
|
||||||
varargs: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait DynHash {
|
pub trait DynHash {
|
||||||
fn dyn_hash(&self, state: &mut dyn Hasher);
|
fn dyn_hash(&self, state: &mut dyn Hasher);
|
||||||
@@ -685,57 +511,6 @@ impl std::fmt::Debug for OwnedSlot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OwnedContextImpl {
|
|
||||||
pub fn set_footprint(&mut self, footprint: Footprint) {
|
|
||||||
self.footprint = Some(footprint);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn with_footprint(mut self, footprint: Footprint) -> Self {
|
|
||||||
self.footprint = Some(footprint);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
pub fn with_real_time(mut self, real_time: f64) -> Self {
|
|
||||||
self.real_time = Some(real_time);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
pub fn with_animation_time(mut self, animation_time: f64) -> Self {
|
|
||||||
self.animation_time = Some(animation_time);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
pub fn with_pointer_position(mut self, pointer_position: DVec2) -> Self {
|
|
||||||
self.pointer_position = Some(pointer_position);
|
|
||||||
self
|
|
||||||
}
|
|
||||||
pub fn with_position(mut self, position: DVec2) -> Self {
|
|
||||||
if let Some(current_position) = &mut self.position {
|
|
||||||
current_position.insert(0, position);
|
|
||||||
} else {
|
|
||||||
self.position = Some(vec![position]);
|
|
||||||
}
|
|
||||||
self
|
|
||||||
}
|
|
||||||
pub fn with_index(mut self, index: usize) -> Self {
|
|
||||||
if let Some(current_index) = &mut self.index {
|
|
||||||
current_index.insert(0, index);
|
|
||||||
} else {
|
|
||||||
self.index = Some(vec![index]);
|
|
||||||
}
|
|
||||||
self
|
|
||||||
}
|
|
||||||
pub fn with_vararg(mut self, value: Box<dyn AnyHash + Send + Sync>) -> Self {
|
|
||||||
assert!(self.varargs.is_none_or(|value| value.is_empty()));
|
|
||||||
self.varargs = Some(Arc::new([value]));
|
|
||||||
self
|
|
||||||
}
|
|
||||||
pub fn into_context(self) -> Option<Arc<Self>> {
|
|
||||||
Some(Arc::new(self))
|
|
||||||
}
|
|
||||||
pub fn erase_parent(mut self) -> Self {
|
|
||||||
self.parent = None;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type SourceId = u64;
|
pub type SourceId = u64;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
|||||||
Reference in New Issue
Block a user