Skip to content

Commit

Permalink
Less allocations probably
Browse files Browse the repository at this point in the history
  • Loading branch information
cecton committed Nov 6, 2023
1 parent bc96cc7 commit 0a9a3bc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/yew/src/html/conversion/into_prop_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl IntoPropValue<VList> for ChildrenRenderer<VNode> {
impl<C: BaseComponent> IntoPropValue<VList> for VChild<C> {
#[inline]
fn into_prop_value(self) -> VList {
VList::from_iter([VNode::from(self)])
VList::from(VNode::from(self))
}
}

Expand All @@ -211,7 +211,7 @@ impl IntoPropValue<ChildrenRenderer<VNode>> for AttrValue {
impl IntoPropValue<VNode> for Vec<VNode> {
#[inline]
fn into_prop_value(self) -> VNode {
VNode::VList(Rc::new(VList::from_iter(self)))
VNode::VList(Rc::new(VList::from(self)))
}
}

Expand Down
28 changes: 28 additions & 0 deletions packages/yew/src/virtual_dom/vlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,34 @@ impl From<Option<Rc<Vec<VNode>>>> for VList {
}
}

impl From<Vec<VNode>> for VList {
fn from(children: Vec<VNode>) -> Self {
if children.is_empty() {
VList::new()
} else {
let mut vlist = VList {
children: Some(Rc::new(children)),
fully_keyed: FullyKeyedState::Unknown,
key: None,
};
vlist.recheck_fully_keyed();
vlist
}
}
}

impl From<VNode> for VList {
fn from(child: VNode) -> Self {
let mut vlist = VList {
children: Some(Rc::new(vec![child])),
fully_keyed: FullyKeyedState::Unknown,
key: None,
};
vlist.recheck_fully_keyed();
vlist
}
}

impl VList {
/// Creates a new empty [VList] instance.
pub const fn new() -> Self {
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/virtual_dom/vnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl VNode {
match *self {
Self::VList(ref mut m) => return Rc::make_mut(m),
_ => {
*self = VNode::VList(Rc::new(VList::from_iter([mem::take(self)])));
*self = VNode::VList(Rc::new(VList::from(mem::take(self))));
}
}
}
Expand Down

0 comments on commit 0a9a3bc

Please sign in to comment.