Skip to content

Commit

Permalink
fix naming of BNode variants
Browse files Browse the repository at this point in the history
  • Loading branch information
WorldSEnder committed Mar 5, 2022
1 parent 0678829 commit bea0708
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 55 deletions.
6 changes: 3 additions & 3 deletions packages/yew/src/dom_bundle/bcomp.rs
Expand Up @@ -92,7 +92,7 @@ impl Reconcilable for VComp {
) -> NodeRef {
match bundle {
// If the existing bundle is the same type, reuse it and update its properties
BNode::BComp(ref mut bcomp)
BNode::Comp(ref mut bcomp)
if self.type_id == bcomp.type_id && self.key == bcomp.key =>
{
self.reconcile(parent_scope, parent, next_sibling, bcomp)
Expand Down Expand Up @@ -216,7 +216,7 @@ impl ComponentRenderState {
let placeholder: Node = document().create_text_node("").into();
insert_node(&placeholder, &parent, next_sibling.get().as_ref());
node_ref.set(Some(placeholder.clone()));
BNode::BRef(placeholder)
BNode::Ref(placeholder)
};
Self {
root_node: placeholder,
Expand All @@ -232,7 +232,7 @@ impl ComponentRenderState {
use super::blist::BList;

Self {
root_node: BNode::BList(BList::new()),
root_node: BNode::List(BList::new()),
parent: None,
next_sibling: NodeRef::default(),
html_sender: Some(tx),
Expand Down
6 changes: 3 additions & 3 deletions packages/yew/src/dom_bundle/blist.rs
Expand Up @@ -101,11 +101,11 @@ impl BNode {
/// Assert that a bundle node is a list, or convert it to a list with a single child
fn make_list(&mut self) -> &mut BList {
match self {
Self::BList(blist) => blist,
Self::List(blist) => blist,
self_ => {
let b = std::mem::replace(self_, BNode::BList(BList::new()));
let b = std::mem::replace(self_, BNode::List(BList::new()));
let self_list = match self_ {
BNode::BList(blist) => blist,
BNode::List(blist) => blist,
_ => unreachable!("just been set to the variant"),
};
let key = b.key().cloned();
Expand Down
86 changes: 43 additions & 43 deletions packages/yew/src/dom_bundle/bnode.rs
Expand Up @@ -11,32 +11,32 @@ use web_sys::{Element, Node};
/// The bundle implementation to [VNode].
pub enum BNode {
/// A bind between `VTag` and `Element`.
BTag(Box<BTag>),
Tag(Box<BTag>),
/// A bind between `VText` and `TextNode`.
BText(BText),
Text(BText),
/// A bind between `VComp` and `Element`.
BComp(BComp),
Comp(BComp),
/// A holder for a list of other nodes.
BList(BList),
List(BList),
/// A portal to another part of the document
BPortal(BPortal),
Portal(BPortal),
/// A holder for any `Node` (necessary for replacing node).
BRef(Node),
Ref(Node),
/// A suspendible document fragment.
BSuspense(Box<BSuspense>),
Suspense(Box<BSuspense>),
}

impl BNode {
/// Get the key of the underlying node
pub(super) fn key(&self) -> Option<&Key> {
match self {
Self::BComp(bsusp) => bsusp.key(),
Self::BList(blist) => blist.key(),
Self::BRef(_) => None,
Self::BTag(btag) => btag.key(),
Self::BText(_) => None,
Self::BPortal(bportal) => bportal.key(),
Self::BSuspense(bsusp) => bsusp.key(),
Self::Comp(bsusp) => bsusp.key(),
Self::List(blist) => blist.key(),
Self::Ref(_) => None,
Self::Tag(btag) => btag.key(),
Self::Text(_) => None,
Self::Portal(bportal) => bportal.key(),
Self::Suspense(bsusp) => bsusp.key(),
}
}
}
Expand All @@ -45,34 +45,34 @@ impl DomBundle for BNode {
/// Remove VNode from parent.
fn detach(self, parent: &Element, parent_to_detach: bool) {
match self {
Self::BTag(vtag) => vtag.detach(parent, parent_to_detach),
Self::BText(btext) => btext.detach(parent, parent_to_detach),
Self::BComp(bsusp) => bsusp.detach(parent, parent_to_detach),
Self::BList(blist) => blist.detach(parent, parent_to_detach),
Self::BRef(ref node) => {
Self::Tag(vtag) => vtag.detach(parent, parent_to_detach),
Self::Text(btext) => btext.detach(parent, parent_to_detach),
Self::Comp(bsusp) => bsusp.detach(parent, parent_to_detach),
Self::List(blist) => blist.detach(parent, parent_to_detach),
Self::Ref(ref node) => {
// Always remove user-defined nodes to clear possible parent references of them
if parent.remove_child(node).is_err() {
console::warn!("Node not found to remove VRef");
}
}
Self::BPortal(bportal) => bportal.detach(parent, parent_to_detach),
Self::BSuspense(bsusp) => bsusp.detach(parent, parent_to_detach),
Self::Portal(bportal) => bportal.detach(parent, parent_to_detach),
Self::Suspense(bsusp) => bsusp.detach(parent, parent_to_detach),
}
}

fn shift(&self, next_parent: &Element, next_sibling: NodeRef) {
match self {
Self::BTag(ref vtag) => vtag.shift(next_parent, next_sibling),
Self::BText(ref btext) => btext.shift(next_parent, next_sibling),
Self::BComp(ref bsusp) => bsusp.shift(next_parent, next_sibling),
Self::BList(ref vlist) => vlist.shift(next_parent, next_sibling),
Self::BRef(ref node) => {
Self::Tag(ref vtag) => vtag.shift(next_parent, next_sibling),
Self::Text(ref btext) => btext.shift(next_parent, next_sibling),
Self::Comp(ref bsusp) => bsusp.shift(next_parent, next_sibling),
Self::List(ref vlist) => vlist.shift(next_parent, next_sibling),
Self::Ref(ref node) => {
next_parent
.insert_before(node, next_sibling.get().as_ref())
.unwrap();
}
Self::BPortal(ref vportal) => vportal.shift(next_parent, next_sibling),
Self::BSuspense(ref vsuspense) => vsuspense.shift(next_parent, next_sibling),
Self::Portal(ref vportal) => vportal.shift(next_parent, next_sibling),
Self::Suspense(ref vsuspense) => vsuspense.shift(next_parent, next_sibling),
}
}
}
Expand Down Expand Up @@ -105,7 +105,7 @@ impl Reconcilable for VNode {
}
VNode::VRef(node) => {
super::insert_node(&node, parent, next_sibling.get().as_ref());
(NodeRef::new(node.clone()), BNode::BRef(node))
(NodeRef::new(node.clone()), BNode::Ref(node))
}
VNode::VPortal(vportal) => {
let (node_ref, portal) = vportal.attach(parent_scope, parent, next_sibling);
Expand Down Expand Up @@ -142,7 +142,7 @@ impl Reconcilable for VNode {
VNode::VList(vlist) => vlist.reconcile_node(parent_scope, parent, next_sibling, bundle),
VNode::VRef(node) => {
let _existing = match bundle {
BNode::BRef(ref n) if &node == n => n,
BNode::Ref(ref n) if &node == n => n,
_ => {
return VNode::VRef(node).replace(
parent_scope,
Expand All @@ -167,55 +167,55 @@ impl Reconcilable for VNode {
impl From<BText> for BNode {
#[inline]
fn from(btext: BText) -> Self {
Self::BText(btext)
Self::Text(btext)
}
}

impl From<BList> for BNode {
#[inline]
fn from(blist: BList) -> Self {
Self::BList(blist)
Self::List(blist)
}
}

impl From<BTag> for BNode {
#[inline]
fn from(btag: BTag) -> Self {
Self::BTag(Box::new(btag))
Self::Tag(Box::new(btag))
}
}

impl From<BComp> for BNode {
#[inline]
fn from(bcomp: BComp) -> Self {
Self::BComp(bcomp)
Self::Comp(bcomp)
}
}

impl From<BPortal> for BNode {
#[inline]
fn from(bportal: BPortal) -> Self {
Self::BPortal(bportal)
Self::Portal(bportal)
}
}

impl From<BSuspense> for BNode {
#[inline]
fn from(bsusp: BSuspense) -> Self {
Self::BSuspense(Box::new(bsusp))
Self::Suspense(Box::new(bsusp))
}
}

impl fmt::Debug for BNode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::BTag(ref vtag) => vtag.fmt(f),
Self::BText(ref btext) => btext.fmt(f),
Self::BComp(ref bsusp) => bsusp.fmt(f),
Self::BList(ref vlist) => vlist.fmt(f),
Self::BRef(ref vref) => write!(f, "VRef ( \"{}\" )", crate::utils::print_node(vref)),
Self::BPortal(ref vportal) => vportal.fmt(f),
Self::BSuspense(ref bsusp) => bsusp.fmt(f),
Self::Tag(ref vtag) => vtag.fmt(f),
Self::Text(ref btext) => btext.fmt(f),
Self::Comp(ref bsusp) => bsusp.fmt(f),
Self::List(ref vlist) => vlist.fmt(f),
Self::Ref(ref vref) => write!(f, "VRef ( \"{}\" )", crate::utils::print_node(vref)),
Self::Portal(ref vportal) => vportal.fmt(f),
Self::Suspense(ref bsusp) => bsusp.fmt(f),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/dom_bundle/bportal.rs
Expand Up @@ -64,7 +64,7 @@ impl Reconcilable for VPortal {
bundle: &mut BNode,
) -> NodeRef {
match bundle {
BNode::BPortal(portal) => self.reconcile(parent_scope, parent, next_sibling, portal),
BNode::Portal(portal) => self.reconcile(parent_scope, parent, next_sibling, portal),
_ => self.replace(parent_scope, parent, next_sibling, bundle),
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/dom_bundle/bsuspense.rs
Expand Up @@ -100,7 +100,7 @@ impl Reconcilable for VSuspense {
) -> NodeRef {
match bundle {
// We only preserve the child state if they are the same suspense.
BNode::BSuspense(m)
BNode::Suspense(m)
if m.key == self.key
&& self.detached_parent.as_ref() == Some(&m.detached_parent) =>
{
Expand Down
6 changes: 3 additions & 3 deletions packages/yew/src/dom_bundle/btag/mod.rs
Expand Up @@ -162,7 +162,7 @@ impl Reconcilable for VTag {
match bundle {
// If the ancestor is a tag of the same type, don't recreate, keep the
// old tag and update its attributes and children.
BNode::BTag(ex) if self.key == ex.key => {
BNode::Tag(ex) if self.key == ex.key => {
if match (&self.inner, &ex.inner) {
(VTagInner::Input(_), BTagInner::Input(_)) => true,
(VTagInner::Textarea { .. }, BTagInner::Textarea { .. }) => true,
Expand Down Expand Up @@ -447,7 +447,7 @@ mod tests {
}

fn assert_btag_ref(node: &BNode) -> &BTag {
if let BNode::BTag(vtag) = node {
if let BNode::Tag(vtag) = node {
return vtag;
}
panic!("should be btag");
Expand All @@ -461,7 +461,7 @@ mod tests {
}

fn assert_btag_mut(node: &mut BNode) -> &mut BTag {
if let BNode::BTag(btag) = node {
if let BNode::Tag(btag) = node {
return btag;
}
panic!("should be btag");
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/dom_bundle/btext.rs
Expand Up @@ -59,7 +59,7 @@ impl Reconcilable for VText {
bundle: &mut BNode,
) -> NodeRef {
match bundle {
BNode::BText(btext) => self.reconcile(parent_scope, parent, next_sibling, btext),
BNode::Text(btext) => self.reconcile(parent_scope, parent, next_sibling, btext),
_ => self.replace(parent_scope, parent, next_sibling, bundle),
}
}
Expand Down

1 comment on commit bea0708

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yew master branch benchmarks (Lower is better)

Benchmark suite Current: bea0708 Previous: 221b4df Ratio
yew-struct-keyed 01_run1k 230.455 229.158 1.01
yew-struct-keyed 02_replace1k 238.869 259.659 0.92
yew-struct-keyed 03_update10th1k_x16 378.4945 442.261 0.86
yew-struct-keyed 04_select1k 75.55449999999999 85.5575 0.88
yew-struct-keyed 05_swap1k 90.0925 95.543 0.94
yew-struct-keyed 06_remove-one-1k 30.7825 32.479 0.95
yew-struct-keyed 07_create10k 2736.8689999999997 2780.947 0.98
yew-struct-keyed 08_create1k-after1k_x2 536.8285000000001 521.0815 1.03
yew-struct-keyed 09_clear1k_x8 264.014 268.7265 0.98
yew-struct-keyed 21_ready-memory 1.2461891174316406 0.9634475708007812 1.29
yew-struct-keyed 22_run-memory 1.4578819274902344 1.4966659545898438 0.97
yew-struct-keyed 23_update5-memory 1.4616203308105469 1.5060157775878906 0.97
yew-struct-keyed 24_run5-memory 1.5109291076660156 1.5109291076660156 1
yew-struct-keyed 25_run-clear-memory 1.124980926513672 1.1288795471191406 1.00
yew-struct-keyed 31_startup-ci 1731.188 1787.7325 0.97
yew-struct-keyed 32_startup-bt 35.51999999999999 35.86199999999999 0.99
yew-struct-keyed 34_startup-totalbytes 359.8974609375 359.8974609375 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.