git.delta.rocks / jrsonnet / refs/commits / a586993e0f09

difftreelog

perf remove allocation on empty string concat

Yaroslav Bolyukin2022-08-07parent: #f51b87e.patch.diff
in: master

1 file changed

modifiedcrates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth
21pub fn evaluate_add_op(s: State, a: &Val, b: &Val) -> Result<Val> {21pub fn evaluate_add_op(s: State, a: &Val, b: &Val) -> Result<Val> {
22 use Val::*;22 use Val::*;
23 Ok(match (a, b) {23 Ok(match (a, b) {
24 (Str(a), Str(b)) if a.is_empty() => Val::Str(b.clone()),
25 (Str(a), Str(b)) if b.is_empty() => Val::Str(a.clone()),
24 (Str(v1), Str(v2)) => Str(((**v1).to_owned() + v2).into()),26 (Str(v1), Str(v2)) => Str(((**v1).to_owned() + v2).into()),
2527
26 // Can't use generic json serialization way, because it depends on number to string concatenation (std.jsonnet:890)28 // Can't use generic json serialization way, because it depends on number to string concatenation (std.jsonnet:890)
27 (Num(a), Str(b)) => Str(format!("{a}{b}").into()),29 (Num(a), Str(b)) => Str(format!("{a}{b}").into()),
28 (Str(a), Num(b)) => Str(format!("{a}{b}").into()),30 (Str(a), Num(b)) => Str(format!("{a}{b}").into()),
2931
32 (Str(a), o) | (o, Str(a)) if a.is_empty() => Val::Str(o.clone().to_string(s)?),
30 (Str(a), o) => Str(format!("{}{}", a, o.clone().to_string(s)?).into()),33 (Str(a), o) => Str(format!("{}{}", a, o.clone().to_string(s)?).into()),
31 (o, Str(a)) => Str(format!("{}{}", o.clone().to_string(s)?, a).into()),34 (o, Str(a)) => Str(format!("{}{}", o.clone().to_string(s)?, a).into()),
3235