clean up some unused code + clippy
This commit is contained in:
1 parent
e81f05fe9d
commit
adff97036d
3 files changed
+35
-46
No files matched your search
@@ -1,7 +1,7 @@
|
||||
use anymap::AnyMap;
|
||||
use parking_lot::RwLock;
|
||||
use rustc_hash::FxHashSet;
|
||||
use std::any::{self, Any, TypeId};
|
||||
use std::any::{Any, TypeId};
|
||||
use std::collections::BTreeMap;
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
@@ -9,7 +9,7 @@ use std::sync::Arc;
|
||||
use crate::node::{FromAnyValue, NodeData};
|
||||
use crate::node_ref::NodeView;
|
||||
use crate::real_dom::RealDom;
|
||||
use crate::tree::{self, Node, TreeStateView};
|
||||
use crate::tree::TreeStateView;
|
||||
use crate::{FxDashMap, FxDashSet, SendAnyMap};
|
||||
use crate::{NodeId, NodeMask};
|
||||
|
||||
@@ -129,22 +129,22 @@ pub trait Pass<V: FromAnyValue + Send = ()>: Any {
|
||||
|
||||
fn validate() {
|
||||
// no type can be a child and parent dependency
|
||||
for type_id in Self::parent_type_ids().into_iter().copied() {
|
||||
for type_id2 in Self::child_type_ids().into_iter().copied() {
|
||||
for type_id in Self::parent_type_ids().iter().copied() {
|
||||
for type_id2 in Self::child_type_ids().iter().copied() {
|
||||
if type_id == type_id2 {
|
||||
panic!("type cannot be both a parent and child dependency");
|
||||
}
|
||||
}
|
||||
}
|
||||
// this type should not be a node dependency
|
||||
for type_id in Self::node_type_ids().into_iter().copied() {
|
||||
for type_id in Self::node_type_ids().iter().copied() {
|
||||
if type_id == TypeId::of::<Self>() {
|
||||
panic!("The current type cannot be a node dependency");
|
||||
}
|
||||
}
|
||||
// no states have the same type id
|
||||
if Self::all_dependanices()
|
||||
.into_iter()
|
||||
.iter()
|
||||
.collect::<FxDashSet<_>>()
|
||||
.len()
|
||||
!= Self::all_dependanices().len()
|
||||
@@ -160,7 +160,7 @@ pub trait Pass<V: FromAnyValue + Send = ()>: Any {
|
||||
Self::validate();
|
||||
TypeErasedPass {
|
||||
this_type_id: TypeId::of::<Self>(),
|
||||
combined_dependancy_type_ids: Self::all_dependanices().into_iter().copied().collect(),
|
||||
combined_dependancy_type_ids: Self::all_dependanices().iter().copied().collect(),
|
||||
parent_dependant: !Self::parent_type_ids().is_empty(),
|
||||
child_dependant: !Self::child_type_ids().is_empty(),
|
||||
dependants: FxHashSet::default(),
|
||||
@@ -169,7 +169,7 @@ pub trait Pass<V: FromAnyValue + Send = ()>: Any {
|
||||
pass: Box::new(
|
||||
|node_id: NodeId, tree: &mut TreeStateView, context: &SendAnyMap| {
|
||||
debug_assert!(!Self::NodeDependencies::type_ids()
|
||||
.into_iter()
|
||||
.iter()
|
||||
.any(|id| *id == TypeId::of::<Self>()));
|
||||
// get all of the states from the tree view
|
||||
// Safety: No node has itself as a parent or child.
|
||||
@@ -181,7 +181,7 @@ pub trait Pass<V: FromAnyValue + Send = ()>: Any {
|
||||
let myself = unsafe { &mut *node_raw };
|
||||
|
||||
myself.pass(
|
||||
NodeView::new(&node_data, Self::NODE_MASK),
|
||||
NodeView::new(node_data, Self::NODE_MASK),
|
||||
node,
|
||||
parent,
|
||||
children,
|
||||
@@ -207,19 +207,19 @@ pub trait Pass<V: FromAnyValue + Send = ()>: Any {
|
||||
|
||||
fn all_dependanices() -> Box<[TypeId]> {
|
||||
let mut dependencies = Self::parent_type_ids().to_vec();
|
||||
dependencies.extend(Self::child_type_ids().into_iter());
|
||||
dependencies.extend(Self::node_type_ids().into_iter());
|
||||
dependencies.extend(Self::child_type_ids().iter());
|
||||
dependencies.extend(Self::node_type_ids().iter());
|
||||
dependencies.into_boxed_slice()
|
||||
}
|
||||
|
||||
fn pass_direction() -> PassDirection {
|
||||
if Self::child_type_ids()
|
||||
.into_iter()
|
||||
.iter()
|
||||
.any(|type_id| *type_id == TypeId::of::<Self>())
|
||||
{
|
||||
PassDirection::ChildToParent
|
||||
} else if Self::parent_type_ids()
|
||||
.into_iter()
|
||||
.iter()
|
||||
.any(|type_id| *type_id == TypeId::of::<Self>())
|
||||
{
|
||||
PassDirection::ParentToChild
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use dioxus_core::{BorrowedAttributeValue, ElementId, Mutations, TemplateNode};
|
||||
use parking_lot::{MappedRwLockReadGuard, MappedRwLockWriteGuard};
|
||||
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use std::any::Any;
|
||||
|
||||
@@ -81,14 +81,6 @@ impl<V: FromAnyValue + Send + Sync> RealDom<V> {
|
||||
}
|
||||
}
|
||||
|
||||
fn mark_dirty(&mut self, node_id: NodeId, mask: NodeMask) {
|
||||
if let Some(node) = self.nodes_updated.get_mut(&node_id) {
|
||||
*node = node.union(&mask);
|
||||
} else {
|
||||
self.nodes_updated.insert(node_id, mask);
|
||||
}
|
||||
}
|
||||
|
||||
fn mark_parent_added_or_removed(&mut self, node_id: NodeId) {
|
||||
self.parent_changed_nodes.insert(node_id);
|
||||
}
|
||||
@@ -247,7 +239,7 @@ impl<V: FromAnyValue + Send + Sync> RealDom<V> {
|
||||
let new_nodes = self.stack.split_off(self.stack.len() - m);
|
||||
let old_node_id = self.element_to_node_id(id);
|
||||
for new in new_nodes {
|
||||
self.tree.insert_before(old_node_id, new);
|
||||
self.insert_before(old_node_id, new);
|
||||
}
|
||||
self.remove(old_node_id);
|
||||
}
|
||||
@@ -255,7 +247,7 @@ impl<V: FromAnyValue + Send + Sync> RealDom<V> {
|
||||
let new_nodes = self.stack.split_off(self.stack.len() - m);
|
||||
let old_node_id = self.load_child(path);
|
||||
for new in new_nodes {
|
||||
self.tree.insert_before(old_node_id, new);
|
||||
self.insert_before(old_node_id, new);
|
||||
}
|
||||
self.remove(old_node_id);
|
||||
}
|
||||
@@ -263,7 +255,7 @@ impl<V: FromAnyValue + Send + Sync> RealDom<V> {
|
||||
let new_nodes = self.stack.split_off(self.stack.len() - m);
|
||||
let old_node_id = self.element_to_node_id(id);
|
||||
for new in new_nodes.into_iter().rev() {
|
||||
self.tree.insert_after(old_node_id, new);
|
||||
self.insert_after(old_node_id, new);
|
||||
}
|
||||
}
|
||||
InsertBefore { id, m } => {
|
||||
@@ -385,12 +377,12 @@ impl<V: FromAnyValue + Send + Sync> RealDom<V> {
|
||||
new_id
|
||||
}
|
||||
|
||||
fn root(&self) -> NodeId {
|
||||
pub fn root(&self) -> NodeId {
|
||||
self.tree.root()
|
||||
}
|
||||
|
||||
fn get(&self, id: NodeId) -> Option<NodeRef<'_, V>> {
|
||||
self.tree.contains(id).then(|| NodeRef { id, dom: &self })
|
||||
pub fn get(&self, id: NodeId) -> Option<NodeRef<'_, V>> {
|
||||
self.tree.contains(id).then_some(NodeRef { id, dom: self })
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, id: NodeId) -> Option<NodeMut<'_, V>> {
|
||||
@@ -462,7 +454,7 @@ impl<V: FromAnyValue + Send + Sync> RealDom<V> {
|
||||
self.tree.remove(id)
|
||||
}
|
||||
|
||||
fn replace(&mut self, old: NodeId, new: NodeId) {
|
||||
pub fn replace(&mut self, old: NodeId, new: NodeId) {
|
||||
if let Some(parent_id) = self.tree.parent_id(old) {
|
||||
self.mark_child_changed(parent_id);
|
||||
self.mark_parent_added_or_removed(new);
|
||||
@@ -470,7 +462,7 @@ impl<V: FromAnyValue + Send + Sync> RealDom<V> {
|
||||
self.tree.replace(old, new);
|
||||
}
|
||||
|
||||
fn insert_before(&mut self, id: NodeId, new: NodeId) {
|
||||
pub fn insert_before(&mut self, id: NodeId, new: NodeId) {
|
||||
if let Some(parent_id) = self.tree.parent_id(id) {
|
||||
self.mark_child_changed(parent_id);
|
||||
self.mark_parent_added_or_removed(new);
|
||||
@@ -478,7 +470,7 @@ impl<V: FromAnyValue + Send + Sync> RealDom<V> {
|
||||
self.tree.insert_before(id, new);
|
||||
}
|
||||
|
||||
fn insert_after(&mut self, id: NodeId, new: NodeId) {
|
||||
pub fn insert_after(&mut self, id: NodeId, new: NodeId) {
|
||||
if let Some(parent_id) = self.tree.parent_id(id) {
|
||||
self.mark_child_changed(parent_id);
|
||||
self.mark_parent_added_or_removed(new);
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
use parking_lot::{
|
||||
MappedRwLockReadGuard, MappedRwLockWriteGuard, RwLock, RwLockReadGuard, RwLockWriteGuard,
|
||||
};
|
||||
use parking_lot::{MappedRwLockReadGuard, RwLock, RwLockReadGuard, RwLockWriteGuard};
|
||||
use rustc_hash::{FxHashMap, FxHasher};
|
||||
use std::any::{Any, TypeId};
|
||||
use std::collections::VecDeque;
|
||||
use std::fmt::Debug;
|
||||
use std::hash::BuildHasherDefault;
|
||||
|
||||
use crate::node::NodeData;
|
||||
use crate::{AnyMapLike, Dependancy};
|
||||
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Debug, Hash)]
|
||||
@@ -109,7 +106,7 @@ impl Tree {
|
||||
tree.nodes.remove(id);
|
||||
}
|
||||
{
|
||||
let mut node_data_mut = self.node_slab_mut();
|
||||
let node_data_mut = self.node_slab_mut();
|
||||
if let Some(parent) = node_data_mut.get(id).unwrap().parent {
|
||||
let parent = node_data_mut.get_mut(parent).unwrap();
|
||||
parent.children.retain(|&child| child != id);
|
||||
@@ -141,7 +138,7 @@ impl Tree {
|
||||
}
|
||||
|
||||
pub fn add_child(&mut self, parent: NodeId, new: NodeId) {
|
||||
let mut node_state = self.node_slab_mut();
|
||||
let node_state = self.node_slab_mut();
|
||||
node_state.get_mut(new).unwrap().parent = Some(parent);
|
||||
let parent = node_state.get_mut(parent).unwrap();
|
||||
parent.children.push(new);
|
||||
@@ -151,7 +148,7 @@ impl Tree {
|
||||
|
||||
pub fn replace(&mut self, old_id: NodeId, new_id: NodeId) {
|
||||
{
|
||||
let mut node_state = self.node_slab_mut();
|
||||
let node_state = self.node_slab_mut();
|
||||
// update the parent's link to the child
|
||||
if let Some(parent_id) = node_state.get(old_id).unwrap().parent {
|
||||
let parent = node_state.get_mut(parent_id).unwrap();
|
||||
@@ -170,7 +167,7 @@ impl Tree {
|
||||
}
|
||||
|
||||
pub fn insert_before(&mut self, old_id: NodeId, new_id: NodeId) {
|
||||
let mut node_state = self.node_slab_mut();
|
||||
let node_state = self.node_slab_mut();
|
||||
let old_node = node_state.get(old_id).unwrap();
|
||||
let parent_id = old_node.parent.expect("tried to insert before root");
|
||||
node_state.get_mut(new_id).unwrap().parent = Some(parent_id);
|
||||
@@ -186,7 +183,7 @@ impl Tree {
|
||||
}
|
||||
|
||||
pub fn insert_after(&mut self, old_id: NodeId, new_id: NodeId) {
|
||||
let mut node_state = self.node_slab_mut();
|
||||
let node_state = self.node_slab_mut();
|
||||
let old_node = node_state.get(old_id).unwrap();
|
||||
let parent_id = old_node.parent.expect("tried to insert before root");
|
||||
node_state.get_mut(new_id).unwrap().parent = Some(parent_id);
|
||||
@@ -271,7 +268,7 @@ impl<'a> DynamicallyBorrowedTree<'a> {
|
||||
nodes.insert(id, MaybeRead::Write(self.nodes.get_slab_mut(id).unwrap()));
|
||||
}
|
||||
{
|
||||
let mut view = TreeStateView {
|
||||
let view = TreeStateView {
|
||||
root: self.root,
|
||||
nodes_data,
|
||||
nodes,
|
||||
@@ -324,7 +321,7 @@ impl<'a, 'b> TreeStateView<'a, 'b> {
|
||||
self.nodes
|
||||
.get_mut(&TypeId::of::<T>())
|
||||
.and_then(|gaurd| match gaurd {
|
||||
MaybeRead::Read(gaurd) => None,
|
||||
MaybeRead::Read(_gaurd) => None,
|
||||
MaybeRead::Write(gaurd) => gaurd.as_any_mut().downcast_mut::<SlabStorage<T>>(),
|
||||
})
|
||||
}
|
||||
@@ -859,7 +856,7 @@ fn get_many_mut_unchecked() {
|
||||
println!("ids: {:#?}", [parent, child, grandchild]);
|
||||
|
||||
{
|
||||
let mut i32_slab = slab.write_slab::<i32>();
|
||||
let i32_slab = slab.write_slab::<i32>();
|
||||
let all =
|
||||
unsafe { i32_slab.get_many_mut_unchecked([parent, child, grandchild].into_iter()) }
|
||||
.unwrap();
|
||||
@@ -867,7 +864,7 @@ fn get_many_mut_unchecked() {
|
||||
}
|
||||
|
||||
{
|
||||
let mut i32_slab = slab.write_slab::<i32>();
|
||||
let i32_slab = slab.write_slab::<i32>();
|
||||
assert!(
|
||||
unsafe { i32_slab.get_many_mut_unchecked([NodeId(3), NodeId(100)].into_iter()) }
|
||||
.is_none()
|
||||
@@ -894,7 +891,7 @@ fn get_many_many_mut_unchecked() {
|
||||
|
||||
println!("slab: {:#?}", slab);
|
||||
|
||||
let mut num_entries = slab.write_slab::<i32>();
|
||||
let num_entries = slab.write_slab::<i32>();
|
||||
|
||||
let all_num = unsafe {
|
||||
num_entries
|
||||
@@ -906,7 +903,7 @@ fn get_many_many_mut_unchecked() {
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(all_num, [&mut 0, &mut 1, &mut 2]);
|
||||
let mut str_entries = slab.write_slab::<&str>();
|
||||
let str_entries = slab.write_slab::<&str>();
|
||||
|
||||
let all_str = unsafe {
|
||||
str_entries
|
||||
|
||||
Reference in new issue
Block a user