-
Notifications
You must be signed in to change notification settings - Fork 0
β‘ Bolt: Optimize string concatenation #475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7564,11 +7564,17 @@ impl Interpreter { | |
| Ok(Value::Text(Arc::from(s))) | ||
| } | ||
| (Value::Text(a), b) => { | ||
| let result = format!("{a}{b}"); | ||
| let b_str = b.to_string_fast(); | ||
| let mut result = String::with_capacity(a.len() + b_str.len()); | ||
| result.push_str(a.as_ref()); | ||
|
Comment on lines
7566
to
+7569
|
||
| result.push_str(b_str.as_ref()); | ||
| Ok(Value::Text(Arc::from(result.as_str()))) | ||
|
Comment on lines
+7568
to
7571
|
||
| } | ||
| (a, Value::Text(b)) => { | ||
| let result = format!("{a}{b}"); | ||
| let a_str = a.to_string_fast(); | ||
| let mut result = String::with_capacity(a_str.len() + b.len()); | ||
| result.push_str(a_str.as_ref()); | ||
| result.push_str(b.as_ref()); | ||
|
Comment on lines
+7567
to
+7577
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Semantic regression risk: mixed-type Line 7567 and Line 7574 switched coercion to Please align Suggested fix (root cause in
|
||
| Ok(Value::Text(Arc::from(result.as_str()))) | ||
|
Comment on lines
+7575
to
7578
|
||
| } | ||
| (a, b) => Err(RuntimeError::new( | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -157,6 +157,18 @@ pub struct ActionSignature { | |||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| impl Value { | ||||||||||||||||||||||||||||||||||||||||||||
| pub fn to_string_fast(&self) -> std::borrow::Cow<'_, str> { | ||||||||||||||||||||||||||||||||||||||||||||
| match self { | ||||||||||||||||||||||||||||||||||||||||||||
| Value::Text(s) => std::borrow::Cow::Borrowed(s.as_ref()), | ||||||||||||||||||||||||||||||||||||||||||||
| Value::Number(n) => std::borrow::Cow::Owned(n.to_string()), | ||||||||||||||||||||||||||||||||||||||||||||
| Value::Bool(b) => std::borrow::Cow::Borrowed(if *b { "yes" } else { "no" }), | ||||||||||||||||||||||||||||||||||||||||||||
| Value::Null => std::borrow::Cow::Borrowed("null"), | ||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π΄
Suggested change
Was this helpful? React with π or π to provide feedback. |
||||||||||||||||||||||||||||||||||||||||||||
| Value::Nothing => std::borrow::Cow::Borrowed("nothing"), | ||||||||||||||||||||||||||||||||||||||||||||
| // For complex types, just fallback to format! | ||||||||||||||||||||||||||||||||||||||||||||
| _ => std::borrow::Cow::Owned(format!("{}", self)), | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+160
to
+169
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Line 165 returns Proposed fix pub fn to_string_fast(&self) -> std::borrow::Cow<'_, str> {
match self {
Value::Text(s) => std::borrow::Cow::Borrowed(s.as_ref()),
Value::Number(n) => std::borrow::Cow::Owned(n.to_string()),
Value::Bool(b) => std::borrow::Cow::Borrowed(if *b { "yes" } else { "no" }),
- Value::Null => std::borrow::Cow::Borrowed("null"),
+ Value::Null => std::borrow::Cow::Borrowed("nothing"),
Value::Nothing => std::borrow::Cow::Borrowed("nothing"),
// For complex types, just fallback to format!
_ => std::borrow::Cow::Owned(format!("{}", self)),
}
}π Committable suggestion
Suggested change
π€ Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| pub fn type_name(&self) -> &'static str { | ||||||||||||||||||||||||||||||||||||||||||||
| match self { | ||||||||||||||||||||||||||||||||||||||||||||
| Value::Number(_) => "Number", | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Entry date appears inconsistent with PR timeline
Line 65 uses
2026-05-18, but this PR was created on2026-04-28. Please align the note date with the actual change date to keep the learning log chronological.π€ Prompt for AI Agents