From d4bdc44bf646176137c6e9bb9c0bcebf709bcaf3 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 15 Sep 2026 08:17:01 +0000 Subject: [PATCH] refactor(stdlib): avoid cloning DslBlockValue in web rendering Extracted logic from dsl_to_html matching on RuntimeValue::DslBlock into a new function, dsl_block_to_html, which operates directly on a reference to DslBlockValue. Updated render_children to use this helper, eliminating the unnecessary clone and wrapper allocation during loop iterations. Co-authored-by: Tcode-Motion <188012755+Tcode-Motion@users.noreply.github.com> --- stdlib/src/web.rs | 238 +++++++++++++++++++++++----------------------- 1 file changed, 119 insertions(+), 119 deletions(-) diff --git a/stdlib/src/web.rs b/stdlib/src/web.rs index 500b9235..d4578845 100644 --- a/stdlib/src/web.rs +++ b/stdlib/src/web.rs @@ -98,9 +98,7 @@ static PAGE_CONTENT: Mutex = Mutex::new(String::new()); fn render_children(html: &mut String, dsl: &techscript_runtime::value::DslBlockValue) { for child in &dsl.children { - html.push_str(&dsl_to_html( - &techscript_runtime::value::RuntimeValue::DslBlock(std::rc::Rc::new(child.clone())), - )); + html.push_str(&dsl_block_to_html(child)); } } @@ -234,129 +232,131 @@ fn render_card(html: &mut String, dsl: &techscript_runtime::value::DslBlockValue /// Convert a DslBlockValue tree to HTML string. fn dsl_to_html(val: &RuntimeValue) -> String { match val { - RuntimeValue::DslBlock(dsl) => { - let mut html = String::new(); - match dsl.kind.as_str() { - "website" => { - render_website(&mut html, dsl); - } - "page" => { - render_page(&mut html, dsl); - } - "hero" => { - render_hero(&mut html, dsl); - } - "section" => { - render_section(&mut html, dsl); - } - "card" => { - render_card(&mut html, dsl); - } - "button" => { - let label = dsl - .properties - .iter() - .find(|p| p.name == "label") - .and_then(|p| p.value.as_ref()) - .map(|v| v.to_string()) - .unwrap_or_else(|| "Button".to_string()); - let _ = write!(html, "", label); - } - "link" => { - let label = dsl - .properties - .iter() - .find(|p| p.name == "label") - .and_then(|p| p.value.as_ref()) - .map(|v| v.to_string()) - .unwrap_or_else(|| "Link".to_string()); - let url = dsl - .properties - .iter() - .find(|p| p.name == "url") - .and_then(|p| p.value.as_ref()) - .map(|v| v.to_string()); - if let Some(u) = url { - let _ = write!(html, "{}", u, label); - } else { - let _ = write!(html, "{}", label); - } - } - "nav" => { - html.push_str(""); - } - "header" => { - html.push_str("
"); - for prop in &dsl.properties { - if prop.name == "title" { - if let Some(RuntimeValue::Str(t)) = &prop.value { - let _ = write!(html, "

{}

", t); - } - } - } - render_children(&mut html, dsl); - html.push_str("
"); - } - "footer" => { - html.push_str(""); } - "input" => { - let placeholder = dsl - .properties - .iter() - .find(|p| p.name == "placeholder") - .and_then(|p| p.value.as_ref()) - .map(|v| v.to_string()); - if let Some(p) = placeholder { - let _ = write!(html, "", p); - } else { - html.push_str(""); + } + render_children(&mut html, dsl); + html.push_str(""); + } + "footer" => { + html.push_str(""); + } + "input" => { + let placeholder = dsl + .properties + .iter() + .find(|p| p.name == "placeholder") + .and_then(|p| p.value.as_ref()) + .map(|v| v.to_string()); + if let Some(p) = placeholder { + let _ = write!(html, "", p); + } else { + html.push_str(""); + } + } + "form" => { + html.push_str("
"); + render_children(&mut html, dsl); + html.push_str("
"); + } + "main" => { + html.push_str("
"); + render_children(&mut html, dsl); + html.push_str("
"); + } + "aside" => { + html.push_str(""); + } + "start" => { + let label = dsl + .properties + .iter() + .find(|p| p.name == "label") + .and_then(|p| p.value.as_ref()) + .map(|v| v.to_string()) + .unwrap_or_else(|| "Get Started".to_string()); + let _ = write!(html, "{}", label); + } + _ => { + let _ = write!(html, "", dsl.kind); } - _ => String::new(), } + html } impl StdlibRegistry {