Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@
## 2024-05-24 - CI formatting issue
**Learning:** cargo fmt needs to run locally before commits to avoid CI formatting errors.
**Action:** Always include a cargo fmt --all step in execution plans before submitting.
## 2024-05-24 - Canvas Property Extraction Optimization
**Learning:** Extracting properties from the `RuntimeValue` DSL property lists in `canvas.rs` was inefficient because the code called `.iter().find()` multiple times for each property. In `stdlib/src/web.rs`, a similar pattern was found where `.iter().find()` was called multiple times on `dsl.properties` for elements like "button", "link", "input", and "start".
**Action:** Replace multiple `.find()` calls with a single-pass `for p in &dsl.properties` loop and `match` or `if` statements on the property names, mutating local fallback variables. This reduces time complexity from O(N^2) to O(N) per block.
81 changes: 46 additions & 35 deletions stdlib/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,30 +263,39 @@ fn dsl_to_html_inner(val: &RuntimeValue, html: &mut String) {
render_card(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 mut label_val = None;
for p in &dsl.properties {
if p.name == "label" {
label_val = p.value.as_ref().map(|v| v.to_string());
break;
}
}
let label = label_val.unwrap_or_else(|| "Button".to_string());
let _ = write!(html, "<button>{}</button>", 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 mut label_val = None;
let mut url_val = None;
for p in &dsl.properties {
match p.name.as_str() {
"label" => {
if label_val.is_none() {
label_val = p.value.as_ref().map(|v| v.to_string());
}
}
"url" => {
if url_val.is_none() {
url_val = p.value.as_ref().map(|v| v.to_string());
}
}
_ => {}
}
if label_val.is_some() && url_val.is_some() {
break;
}
}
let label = label_val.unwrap_or_else(|| "Link".to_string());
if let Some(u) = url_val {
let _ = write!(html, "<a href=\"{}\">{}</a>", u, label);
} else {
let _ = write!(html, "<a href=\"#\">{}</a>", label);
Expand Down Expand Up @@ -322,13 +331,14 @@ fn dsl_to_html_inner(val: &RuntimeValue, html: &mut String) {
html.push_str("</footer>");
}
"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 mut placeholder_val = None;
for p in &dsl.properties {
if p.name == "placeholder" {
placeholder_val = p.value.as_ref().map(|v| v.to_string());
break;
}
}
if let Some(p) = placeholder_val {
let _ = write!(html, "<input placeholder=\"{}\">", p);
} else {
html.push_str("<input>");
Expand All @@ -350,13 +360,14 @@ fn dsl_to_html_inner(val: &RuntimeValue, html: &mut String) {
html.push_str("</aside>");
}
"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 mut label_val = None;
for p in &dsl.properties {
if p.name == "label" {
label_val = p.value.as_ref().map(|v| v.to_string());
break;
}
}
let label = label_val.unwrap_or_else(|| "Get Started".to_string());
let _ = write!(html, "<a class=\"start-button\" href=\"#\">{}</a>", label);
}
_ => {
Expand Down
Loading