|
|
@ -1,10 +1,12 @@ |
|
|
|
//! Implements object shapes.
|
|
|
|
//! Implements object shapes.
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) mod property_table; |
|
|
|
pub(crate) mod property_table; |
|
|
|
|
|
|
|
mod root_shape; |
|
|
|
pub(crate) mod shared_shape; |
|
|
|
pub(crate) mod shared_shape; |
|
|
|
pub(crate) mod slot; |
|
|
|
pub(crate) mod slot; |
|
|
|
pub(crate) mod unique_shape; |
|
|
|
pub(crate) mod unique_shape; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub use root_shape::RootShape; |
|
|
|
pub use shared_shape::SharedShape; |
|
|
|
pub use shared_shape::SharedShape; |
|
|
|
pub(crate) use unique_shape::UniqueShape; |
|
|
|
pub(crate) use unique_shape::UniqueShape; |
|
|
|
|
|
|
|
|
|
|
@ -63,8 +65,9 @@ pub struct Shape { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl Default for Shape { |
|
|
|
impl Default for Shape { |
|
|
|
|
|
|
|
#[inline] |
|
|
|
fn default() -> Self { |
|
|
|
fn default() -> Self { |
|
|
|
Self::unique(UniqueShape::default()) |
|
|
|
UniqueShape::default().into() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -75,20 +78,6 @@ impl Shape { |
|
|
|
/// NOTE: This only applies to [`SharedShape`].
|
|
|
|
/// NOTE: This only applies to [`SharedShape`].
|
|
|
|
const TRANSITION_COUNT_MAX: u16 = 1024; |
|
|
|
const TRANSITION_COUNT_MAX: u16 = 1024; |
|
|
|
|
|
|
|
|
|
|
|
/// Create a [`Shape`] from a [`SharedShape`].
|
|
|
|
|
|
|
|
pub(crate) fn shared(inner: SharedShape) -> Self { |
|
|
|
|
|
|
|
Self { |
|
|
|
|
|
|
|
inner: Inner::Shared(inner), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Create a [`Shape`] from a [`UniqueShape`].
|
|
|
|
|
|
|
|
pub(crate) const fn unique(shape: UniqueShape) -> Self { |
|
|
|
|
|
|
|
Self { |
|
|
|
|
|
|
|
inner: Inner::Unique(shape), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns `true` if it's a shared shape, `false` otherwise.
|
|
|
|
/// Returns `true` if it's a shared shape, `false` otherwise.
|
|
|
|
#[inline] |
|
|
|
#[inline] |
|
|
|
pub const fn is_shared(&self) -> bool { |
|
|
|
pub const fn is_shared(&self) -> bool { |
|
|
@ -116,11 +105,11 @@ impl Shape { |
|
|
|
Inner::Shared(shape) => { |
|
|
|
Inner::Shared(shape) => { |
|
|
|
let shape = shape.insert_property_transition(key); |
|
|
|
let shape = shape.insert_property_transition(key); |
|
|
|
if shape.transition_count() >= Self::TRANSITION_COUNT_MAX { |
|
|
|
if shape.transition_count() >= Self::TRANSITION_COUNT_MAX { |
|
|
|
return Self::unique(shape.to_unique()); |
|
|
|
return shape.to_unique().into(); |
|
|
|
} |
|
|
|
} |
|
|
|
Self::shared(shape) |
|
|
|
shape.into() |
|
|
|
} |
|
|
|
} |
|
|
|
Inner::Unique(shape) => Self::unique(shape.insert_property_transition(key)), |
|
|
|
Inner::Unique(shape) => shape.insert_property_transition(key).into(), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -137,9 +126,9 @@ impl Shape { |
|
|
|
let change_transition = shape.change_attributes_transition(key); |
|
|
|
let change_transition = shape.change_attributes_transition(key); |
|
|
|
let shape = |
|
|
|
let shape = |
|
|
|
if change_transition.shape.transition_count() >= Self::TRANSITION_COUNT_MAX { |
|
|
|
if change_transition.shape.transition_count() >= Self::TRANSITION_COUNT_MAX { |
|
|
|
Self::unique(change_transition.shape.to_unique()) |
|
|
|
change_transition.shape.to_unique().into() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Self::shared(change_transition.shape) |
|
|
|
change_transition.shape.into() |
|
|
|
}; |
|
|
|
}; |
|
|
|
ChangeTransition { |
|
|
|
ChangeTransition { |
|
|
|
shape, |
|
|
|
shape, |
|
|
@ -158,11 +147,11 @@ impl Shape { |
|
|
|
Inner::Shared(shape) => { |
|
|
|
Inner::Shared(shape) => { |
|
|
|
let shape = shape.remove_property_transition(key); |
|
|
|
let shape = shape.remove_property_transition(key); |
|
|
|
if shape.transition_count() >= Self::TRANSITION_COUNT_MAX { |
|
|
|
if shape.transition_count() >= Self::TRANSITION_COUNT_MAX { |
|
|
|
return Self::unique(shape.to_unique()); |
|
|
|
return shape.to_unique().into(); |
|
|
|
} |
|
|
|
} |
|
|
|
Self::shared(shape) |
|
|
|
shape.into() |
|
|
|
} |
|
|
|
} |
|
|
|
Inner::Unique(shape) => Self::unique(shape.remove_property_transition(key)), |
|
|
|
Inner::Unique(shape) => shape.remove_property_transition(key).into(), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -172,11 +161,11 @@ impl Shape { |
|
|
|
Inner::Shared(shape) => { |
|
|
|
Inner::Shared(shape) => { |
|
|
|
let shape = shape.change_prototype_transition(prototype); |
|
|
|
let shape = shape.change_prototype_transition(prototype); |
|
|
|
if shape.transition_count() >= Self::TRANSITION_COUNT_MAX { |
|
|
|
if shape.transition_count() >= Self::TRANSITION_COUNT_MAX { |
|
|
|
return Self::unique(shape.to_unique()); |
|
|
|
return shape.to_unique().into(); |
|
|
|
} |
|
|
|
} |
|
|
|
Self::shared(shape) |
|
|
|
shape.into() |
|
|
|
} |
|
|
|
} |
|
|
|
Inner::Unique(shape) => Self::unique(shape.change_prototype_transition(prototype)), |
|
|
|
Inner::Unique(shape) => shape.change_prototype_transition(prototype).into(), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -215,3 +204,19 @@ impl Shape { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<UniqueShape> for Shape { |
|
|
|
|
|
|
|
fn from(shape: UniqueShape) -> Self { |
|
|
|
|
|
|
|
Self { |
|
|
|
|
|
|
|
inner: Inner::Unique(shape), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<SharedShape> for Shape { |
|
|
|
|
|
|
|
fn from(shape: SharedShape) -> Self { |
|
|
|
|
|
|
|
Self { |
|
|
|
|
|
|
|
inner: Inner::Shared(shape), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|