Skip to content

Commit

Permalink
More optimisation.
Browse files Browse the repository at this point in the history
  • Loading branch information
futursolo committed May 22, 2022
1 parent bcf4182 commit ff0ad94
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/yew/src/virtual_dom/vcomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ mod feat_ssr {
use crate::html::AnyScope;

impl VComp {
#[inline]
pub(crate) async fn render_into_stream(
&self,
tx: &mut UnboundedSender<String>,
Expand Down
13 changes: 10 additions & 3 deletions packages/yew/src/virtual_dom/vnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,13 @@ mod feat_ssr {
parent_scope: &'a AnyScope,
hydratable: bool,
) -> LocalBoxFuture<'a, ()> {
async move {
match self {
async fn render_into_stream_(
this: &VNode,
tx: &mut UnboundedSender<String>,
parent_scope: &AnyScope,
hydratable: bool,
) {
match this {
VNode::VTag(vtag) => {
vtag.render_into_stream(tx, parent_scope, hydratable).await
}
Expand Down Expand Up @@ -191,7 +196,9 @@ mod feat_ssr {
}
}
}
.boxed_local()

async move { render_into_stream_(self, tx, parent_scope, hydratable).await }
.boxed_local()
}
}
}
19 changes: 14 additions & 5 deletions packages/yew/src/virtual_dom/vtag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,16 +450,25 @@ mod feat_ssr {
hydratable: bool,
) {
// Preallocate a String that is big enough for most elements.
let mut start_tag = String::with_capacity(50);
let mut start_tag = String::with_capacity(64);
start_tag.push('<');
start_tag.push_str(self.tag());

let write_attr = |w: &mut String, name: &str, val: Option<&str>| {
write!(w, " {}", name).unwrap();

if let Some(m) = val {
write!(w, "=\"{}\"", html_escape::encode_double_quoted_attribute(m)).unwrap();
match val {
Some(val) => {
write!(
w,
"{}=\"{}\"",
name,
html_escape::encode_double_quoted_attribute(val)
)
}
None => {
write!(w, " {}", name)
}
}
.unwrap();
};

if let VTagInner::Input(_) = self.inner {
Expand Down

0 comments on commit ff0ad94

Please sign in to comment.