render optimizations (#585)
This commit is contained in:
1 parent
fb2f3e68ff
commit
23c48cf795
2 files changed
+27
-15
No files matched your search
@@ -65,8 +65,15 @@ pub fn rsx_without_templates(s: TokenStream) -> TokenStream {
|
||||
pub fn render(s: TokenStream) -> TokenStream {
|
||||
match syn::parse::<rsx::CallBody>(s) {
|
||||
Err(err) => err.to_compile_error().into(),
|
||||
Ok(body) => quote::quote! {
|
||||
cx.render(#body)
|
||||
Ok(body) => {
|
||||
let mut inner = proc_macro2::TokenStream::new();
|
||||
body.to_tokens_without_lazynodes(&mut inner);
|
||||
quote::quote! {
|
||||
{
|
||||
let __cx = NodeFactory::new(&cx.scope);
|
||||
Some(#inner)
|
||||
}
|
||||
}
|
||||
}
|
||||
.into_token_stream()
|
||||
.into(),
|
||||
|
||||
+18
-13
@@ -67,20 +67,9 @@ impl Parse for CallBody {
|
||||
/// Serialize the same way, regardless of flavor
|
||||
impl ToTokens for CallBody {
|
||||
fn to_tokens(&self, out_tokens: &mut TokenStream2) {
|
||||
let template = TemplateBuilder::from_roots(self.roots.clone());
|
||||
let inner = if let Some(template) = template {
|
||||
quote! { #template }
|
||||
} else {
|
||||
let children = &self.roots;
|
||||
if children.len() == 1 {
|
||||
let inner = &self.roots[0];
|
||||
quote! { #inner }
|
||||
} else {
|
||||
quote! { __cx.fragment_root([ #(#children),* ]) }
|
||||
}
|
||||
};
|
||||
let mut inner = TokenStream2::new();
|
||||
self.to_tokens_without_lazynodes(&mut inner);
|
||||
|
||||
// Otherwise we just build the LazyNode wrapper
|
||||
out_tokens.append_all(quote! {
|
||||
LazyNodes::new(move |__cx: NodeFactory| -> VNode {
|
||||
use dioxus_elements::{GlobalAttributes, SvgAttributes};
|
||||
@@ -107,4 +96,20 @@ impl CallBody {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub fn to_tokens_without_lazynodes(&self, out_tokens: &mut TokenStream2) {
|
||||
let template = TemplateBuilder::from_roots(self.roots.clone());
|
||||
let inner = if let Some(template) = template {
|
||||
quote! { #template }
|
||||
} else {
|
||||
let children = &self.roots;
|
||||
if children.len() == 1 {
|
||||
let inner = &self.roots[0];
|
||||
quote! { #inner }
|
||||
} else {
|
||||
quote! { __cx.fragment_root([ #(#children),* ]) }
|
||||
}
|
||||
};
|
||||
out_tokens.append_all(inner);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user