wip: rename
This commit is contained in:
1 parent
93d4b8ca7c
commit
36d89beb34
20 files changed
+243
-7549
No files matched your search
+109
-94
@@ -198,12 +198,13 @@ impl<'bump> DiffStack<'bump> {
|
||||
}
|
||||
}
|
||||
|
||||
fn push_subtree(&mut self) {
|
||||
self.nodes_created_stack.push(0);
|
||||
self.instructions.push(DiffInstruction::Mount {
|
||||
and: MountType::Append,
|
||||
});
|
||||
}
|
||||
// todo: subtrees
|
||||
// fn push_subtree(&mut self) {
|
||||
// self.nodes_created_stack.push(0);
|
||||
// self.instructions.push(DiffInstruction::Mount {
|
||||
// and: MountType::Append,
|
||||
// });
|
||||
// }
|
||||
|
||||
fn push_nodes_created(&mut self, count: usize) {
|
||||
self.nodes_created_stack.push(count);
|
||||
@@ -289,7 +290,7 @@ impl<'bump> DiffState<'bump> {
|
||||
1
|
||||
}
|
||||
|
||||
VNode::Linked(linked) => {
|
||||
VNode::Portal(linked) => {
|
||||
let node = unsafe { &*linked.node };
|
||||
let node: &VNode = unsafe { std::mem::transmute(node) };
|
||||
self.push_all_nodes(node)
|
||||
@@ -357,8 +358,8 @@ impl<'bump> DiffState<'bump> {
|
||||
VNode::Placeholder(anchor) => self.create_anchor_node(anchor, node),
|
||||
VNode::Element(element) => self.create_element_node(element, node),
|
||||
VNode::Fragment(frag) => self.create_fragment_node(frag),
|
||||
VNode::Component(component) => self.create_component_node(component),
|
||||
VNode::Linked(linked) => self.create_linked_node(linked),
|
||||
VNode::Component(component) => self.create_component_node(*component),
|
||||
VNode::Portal(linked) => self.create_linked_node(linked),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,14 +423,18 @@ impl<'bump> DiffState<'bump> {
|
||||
self.mutations.set_attribute(attr, real_id.as_u64());
|
||||
}
|
||||
|
||||
if !children.is_empty() && children.len() == 1 {
|
||||
if let VNode::Text(vtext) = children[0] {
|
||||
self.mutations.set_text(vtext.text, real_id.as_u64());
|
||||
return;
|
||||
}
|
||||
}
|
||||
// todo: the settext optimization
|
||||
|
||||
self.stack.create_children(children, MountType::Append);
|
||||
// if children.len() == 1 {
|
||||
// if let VNode::Text(vtext) = children[0] {
|
||||
// self.mutations.set_text(vtext.text, real_id.as_u64());
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
if !children.is_empty() {
|
||||
self.stack.create_children(children, MountType::Append);
|
||||
}
|
||||
}
|
||||
|
||||
fn create_fragment_node(&mut self, frag: &'bump VFragment<'bump>) {
|
||||
@@ -454,8 +459,6 @@ impl<'bump> DiffState<'bump> {
|
||||
self.scopes
|
||||
.new_with_key(fc_ptr, caller, parent_scope, container, height, subtree);
|
||||
|
||||
log::debug!("container for scope {:?} is {:?}", new_idx, container);
|
||||
|
||||
// Actually initialize the caller's slot with the right address
|
||||
vcomponent.associated_scope.set(Some(new_idx));
|
||||
|
||||
@@ -463,18 +466,12 @@ impl<'bump> DiffState<'bump> {
|
||||
let cur_scope = self.scopes.get_scope(&parent_idx).unwrap();
|
||||
let extended = unsafe { std::mem::transmute(vcomponent) };
|
||||
cur_scope.items.borrow_mut().borrowed_props.push(extended);
|
||||
} else {
|
||||
// the props are currently bump allocated but we need to move them to the heap
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// add noderefs to current noderef list Noderefs
|
||||
// add effects to current effect list Effects
|
||||
let new_component = self.scopes.get_scope(&new_idx).unwrap();
|
||||
|
||||
log::debug!(
|
||||
"initializing component {:?} with height {:?}",
|
||||
new_idx,
|
||||
height + 1
|
||||
);
|
||||
// TODO: add noderefs to current noderef list Noderefs
|
||||
let _new_component = self.scopes.get_scope(&new_idx).unwrap();
|
||||
|
||||
// Run the scope for one iteration to initialize it
|
||||
if self.scopes.run_scope(&new_idx) {
|
||||
@@ -482,16 +479,17 @@ impl<'bump> DiffState<'bump> {
|
||||
let nextnode = self.scopes.fin_head(&new_idx);
|
||||
self.stack.create_component(new_idx, nextnode);
|
||||
|
||||
if new_component.is_subtree_root.get() {
|
||||
self.stack.push_subtree();
|
||||
}
|
||||
// todo: subtrees
|
||||
// if new_component.is_subtree_root.get() {
|
||||
// self.stack.push_subtree();
|
||||
// }
|
||||
}
|
||||
|
||||
// Finally, insert this scope as a seen node.
|
||||
self.seen_scopes.insert(new_idx);
|
||||
}
|
||||
|
||||
fn create_linked_node(&mut self, link: &'bump NodeLink) {
|
||||
fn create_linked_node(&mut self, link: &'bump VPortal) {
|
||||
if link.scope_id.get().is_none() {
|
||||
if let Some(cur_scope) = self.stack.current_scope() {
|
||||
link.scope_id.set(Some(cur_scope));
|
||||
@@ -513,17 +511,17 @@ impl<'bump> DiffState<'bump> {
|
||||
self.diff_text_nodes(old, new, old_node, new_node);
|
||||
}
|
||||
(Component(old), Component(new)) => {
|
||||
self.diff_component_nodes(old_node, new_node, old, new)
|
||||
self.diff_component_nodes(old_node, new_node, *old, *new)
|
||||
}
|
||||
(Fragment(old), Fragment(new)) => self.diff_fragment_nodes(old, new),
|
||||
(Placeholder(old), Placeholder(new)) => new.dom_id.set(old.dom_id.get()),
|
||||
(Element(old), Element(new)) => self.diff_element_nodes(old, new, old_node, new_node),
|
||||
(Linked(old), Linked(new)) => self.diff_linked_nodes(old, new),
|
||||
(Portal(old), Portal(new)) => self.diff_linked_nodes(old, new),
|
||||
|
||||
// Anything else is just a basic replace and create
|
||||
(
|
||||
Linked(_) | Component(_) | Fragment(_) | Text(_) | Element(_) | Placeholder(_),
|
||||
Linked(_) | Component(_) | Fragment(_) | Text(_) | Element(_) | Placeholder(_),
|
||||
Portal(_) | Component(_) | Fragment(_) | Text(_) | Element(_) | Placeholder(_),
|
||||
Portal(_) | Component(_) | Fragment(_) | Text(_) | Element(_) | Placeholder(_),
|
||||
) => self
|
||||
.stack
|
||||
.create_node(new_node, MountType::Replace { old: old_node }),
|
||||
@@ -636,60 +634,76 @@ impl<'bump> DiffState<'bump> {
|
||||
}
|
||||
}
|
||||
|
||||
match (old.children.len(), new.children.len()) {
|
||||
(0, 0) => {}
|
||||
(1, 1) => {
|
||||
let old1 = &old.children[0];
|
||||
let new1 = &new.children[0];
|
||||
|
||||
match (old1, new1) {
|
||||
(VNode::Text(old_text), VNode::Text(new_text)) => {
|
||||
if old_text.text != new_text.text {
|
||||
self.mutations.set_text(new_text.text, root.as_u64());
|
||||
}
|
||||
}
|
||||
(VNode::Text(_old_text), _) => {
|
||||
self.stack.element_stack.push(root);
|
||||
self.stack.instructions.push(DiffInstruction::PopElement);
|
||||
self.stack.create_node(new1, MountType::Append);
|
||||
}
|
||||
(_, VNode::Text(new_text)) => {
|
||||
self.remove_nodes([old1], false);
|
||||
self.mutations.set_text(new_text.text, root.as_u64());
|
||||
}
|
||||
_ => {
|
||||
self.stack.element_stack.push(root);
|
||||
self.stack.instructions.push(DiffInstruction::PopElement);
|
||||
self.diff_children(old.children, new.children);
|
||||
}
|
||||
}
|
||||
}
|
||||
(0, 1) => {
|
||||
if let VNode::Text(text) = &new.children[0] {
|
||||
self.mutations.set_text(text.text, root.as_u64());
|
||||
} else {
|
||||
self.stack.element_stack.push(root);
|
||||
self.stack.instructions.push(DiffInstruction::PopElement);
|
||||
}
|
||||
}
|
||||
(0, _) => {
|
||||
self.mutations.edits.push(PushRoot {
|
||||
root: root.as_u64(),
|
||||
});
|
||||
self.stack.element_stack.push(root);
|
||||
self.stack.instructions.push(DiffInstruction::PopElement);
|
||||
self.stack.create_children(new.children, MountType::Append);
|
||||
}
|
||||
(_, 0) => {
|
||||
self.remove_nodes(old.children, false);
|
||||
self.mutations.set_text("", root.as_u64());
|
||||
}
|
||||
(_, _) => {
|
||||
self.stack.element_stack.push(root);
|
||||
self.stack.instructions.push(DiffInstruction::PopElement);
|
||||
self.diff_children(old.children, new.children);
|
||||
}
|
||||
if old.children.is_empty() && !new.children.is_empty() {
|
||||
self.mutations.edits.push(PushRoot {
|
||||
root: root.as_u64(),
|
||||
});
|
||||
self.stack.element_stack.push(root);
|
||||
self.stack.instructions.push(DiffInstruction::PopElement);
|
||||
self.stack.create_children(new.children, MountType::Append);
|
||||
} else {
|
||||
self.stack.element_stack.push(root);
|
||||
self.stack.instructions.push(DiffInstruction::PopElement);
|
||||
self.diff_children(old.children, new.children);
|
||||
}
|
||||
|
||||
// todo: this is for the "settext" optimization
|
||||
// it works, but i'm not sure if it's the direction we want to take
|
||||
|
||||
// match (old.children.len(), new.children.len()) {
|
||||
// (0, 0) => {}
|
||||
// (1, 1) => {
|
||||
// let old1 = &old.children[0];
|
||||
// let new1 = &new.children[0];
|
||||
|
||||
// match (old1, new1) {
|
||||
// (VNode::Text(old_text), VNode::Text(new_text)) => {
|
||||
// if old_text.text != new_text.text {
|
||||
// self.mutations.set_text(new_text.text, root.as_u64());
|
||||
// }
|
||||
// }
|
||||
// (VNode::Text(_old_text), _) => {
|
||||
// self.stack.element_stack.push(root);
|
||||
// self.stack.instructions.push(DiffInstruction::PopElement);
|
||||
// self.stack.create_node(new1, MountType::Append);
|
||||
// }
|
||||
// (_, VNode::Text(new_text)) => {
|
||||
// self.remove_nodes([old1], false);
|
||||
// self.mutations.set_text(new_text.text, root.as_u64());
|
||||
// }
|
||||
// _ => {
|
||||
// self.stack.element_stack.push(root);
|
||||
// self.stack.instructions.push(DiffInstruction::PopElement);
|
||||
// self.diff_children(old.children, new.children);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// (0, 1) => {
|
||||
// if let VNode::Text(text) = &new.children[0] {
|
||||
// self.mutations.set_text(text.text, root.as_u64());
|
||||
// } else {
|
||||
// self.stack.element_stack.push(root);
|
||||
// self.stack.instructions.push(DiffInstruction::PopElement);
|
||||
// }
|
||||
// }
|
||||
// (0, _) => {
|
||||
// self.mutations.edits.push(PushRoot {
|
||||
// root: root.as_u64(),
|
||||
// });
|
||||
// self.stack.element_stack.push(root);
|
||||
// self.stack.instructions.push(DiffInstruction::PopElement);
|
||||
// self.stack.create_children(new.children, MountType::Append);
|
||||
// }
|
||||
// (_, 0) => {
|
||||
// self.remove_nodes(old.children, false);
|
||||
// self.mutations.set_text("", root.as_u64());
|
||||
// }
|
||||
// (_, _) => {
|
||||
// self.stack.element_stack.push(root);
|
||||
// self.stack.instructions.push(DiffInstruction::PopElement);
|
||||
// self.diff_children(old.children, new.children);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
fn diff_component_nodes(
|
||||
@@ -721,6 +735,7 @@ impl<'bump> DiffState<'bump> {
|
||||
.get_scope_mut(&scope_addr)
|
||||
.unwrap_or_else(|| panic!("could not find {:?}", scope_addr))
|
||||
};
|
||||
|
||||
scope.caller = unsafe { std::mem::transmute(new.caller) };
|
||||
|
||||
// React doesn't automatically memoize, but we do.
|
||||
@@ -754,7 +769,7 @@ impl<'bump> DiffState<'bump> {
|
||||
self.diff_children(old.children, new.children);
|
||||
}
|
||||
|
||||
fn diff_linked_nodes(&mut self, old: &'bump NodeLink, new: &'bump NodeLink) {
|
||||
fn diff_linked_nodes(&mut self, old: &'bump VPortal, new: &'bump VPortal) {
|
||||
if !std::ptr::eq(old.node, new.node) {
|
||||
// if the ptrs are the same then theyr're the same
|
||||
let old: &VNode = unsafe { std::mem::transmute(&*old.node) };
|
||||
@@ -1207,7 +1222,7 @@ impl<'bump> DiffState<'bump> {
|
||||
VNode::Text(t) => break t.dom_id.get(),
|
||||
VNode::Element(t) => break t.dom_id.get(),
|
||||
VNode::Placeholder(t) => break t.dom_id.get(),
|
||||
VNode::Linked(l) => {
|
||||
VNode::Portal(l) => {
|
||||
let node: &VNode = unsafe { std::mem::transmute(&*l.node) };
|
||||
self.find_last_element(node);
|
||||
}
|
||||
@@ -1235,7 +1250,7 @@ impl<'bump> DiffState<'bump> {
|
||||
let scope_id = el.associated_scope.get().unwrap();
|
||||
search_node = Some(self.scopes.root_node(&scope_id));
|
||||
}
|
||||
VNode::Linked(link) => {
|
||||
VNode::Portal(link) => {
|
||||
let node = unsafe { std::mem::transmute(&*link.node) };
|
||||
search_node = Some(node);
|
||||
}
|
||||
@@ -1281,7 +1296,7 @@ impl<'bump> DiffState<'bump> {
|
||||
self.scopes.try_remove(&scope_id).unwrap();
|
||||
}
|
||||
|
||||
VNode::Linked(l) => {
|
||||
VNode::Portal(l) => {
|
||||
let node: &'bump VNode<'bump> = unsafe { std::mem::transmute(&*l.node) };
|
||||
self.replace_node(node, nodes_created);
|
||||
}
|
||||
@@ -1330,7 +1345,7 @@ impl<'bump> DiffState<'bump> {
|
||||
self.remove_nodes(f.children, gen_muts);
|
||||
}
|
||||
|
||||
VNode::Linked(l) => {
|
||||
VNode::Portal(l) => {
|
||||
let node = unsafe { std::mem::transmute(&*l.node) };
|
||||
self.remove_nodes(Some(node), gen_muts);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user