Skip to content

Commit a5f9e7f

Browse files
⚡ Bolt: Optimize Value Display formatting and fix formatting issues
Refactor `fmt::Display` implementation for `Value` to write directly to the `fmt::Formatter`, eliminating multiple `String` allocations, `format!` usage, and `.clone()` calls during display formatting. Also applied `cargo fmt` to resolve CI failures. Co-authored-by: ashyanSpada <22587148+ashyanSpada@users.noreply.github.com>
1 parent 13df1c4 commit a5f9e7f

2 files changed

Lines changed: 5 additions & 11 deletions

File tree

benches/display_expression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use criterion::{criterion_group, criterion_main, Criterion, black_box};
1+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
22
use expression_engine::{parse_expression, ExprAST};
33

44
fn bench_display_expression(c: &mut Criterion) {

src/parser.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,16 @@ impl<'a> fmt::Display for ExprAST<'a> {
5252
Self::Unary(op, rhs) => {
5353
write!(f, "Unary AST: Op: {}, Rhs: {}", op, rhs)
5454
}
55-
Self::Binary(op, lhs, rhs) => write!(
56-
f,
57-
"Binary AST: Op: {}, Lhs: {}, Rhs: {}",
58-
op,
59-
lhs,
60-
rhs
61-
),
55+
Self::Binary(op, lhs, rhs) => {
56+
write!(f, "Binary AST: Op: {}, Lhs: {}, Rhs: {}", op, lhs, rhs)
57+
}
6258
Self::Postfix(lhs, op) => {
6359
write!(f, "Postfix AST: Lhs: {}, Op: {}", lhs, op,)
6460
}
6561
Self::Ternary(condition, lhs, rhs) => write!(
6662
f,
6763
"Ternary AST: Condition: {}, Lhs: {}, Rhs: {}",
68-
condition,
69-
lhs,
70-
rhs
64+
condition, lhs, rhs
7165
),
7266
Self::Reference(name) => write!(f, "Reference AST: reference: {}", name),
7367
Self::Function(name, params) => {

0 commit comments

Comments
 (0)