diff options
author | sterni <sternenseemann@systemli.org> | 2022-09-15T15·42+0200 |
---|---|---|
committer | sterni <sternenseemann@systemli.org> | 2022-09-15T15·52+0000 |
commit | 05958703410d37f874c4705cabbbba2082c555f7 (patch) | |
tree | 0a8130fac7ff003d081dcc10b1af6333079791bd /tvix | |
parent | 4eb33e82ff418de0ad811a0d3afffac84831fac4 (diff) |
refactor(tvix/eval): don't move parts Vec in compile_str_parts r/4861
This allows us to get rid of the count local variable which was a bit confusing. Calling parts.len() multiple times is fine, since the length doesn't need to be computed. Change-Id: I4f626729ad1bf23a93cb701385c3f4b50c57456d Reviewed-on: https://cl.tvl.fyi/c/depot/+/6584 Autosubmit: sterni <sternenseemann@systemli.org> Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix')
-rw-r--r-- | tvix/eval/src/compiler/mod.rs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index f0c9d0dc432f..15ff0ea309d3 100644 --- a/tvix/eval/src/compiler/mod.rs +++ b/tvix/eval/src/compiler/mod.rs @@ -266,13 +266,11 @@ impl Compiler<'_, '_> { parent_node: &ast::Str, parts: Vec<ast::InterpolPart<String>>, ) { - let count = parts.len(); - // The string parts are produced in literal order, however // they need to be reversed on the stack in order to // efficiently create the real string in case of // interpolation. - for part in parts.into_iter().rev() { + for part in parts.iter().rev() { match part { // Interpolated expressions are compiled as normal and // dealt with by the VM before being assembled into @@ -281,17 +279,17 @@ impl Compiler<'_, '_> { ast::InterpolPart::Interpolation(ipol) => { self.compile(slot, ipol.expr().unwrap()); // implicitly forces as well - self.push_op(OpCode::OpCoerceToString, &ipol); + self.push_op(OpCode::OpCoerceToString, ipol); } ast::InterpolPart::Literal(lit) => { - self.emit_constant(Value::String(lit.into()), parent_node); + self.emit_constant(Value::String(lit.as_str().into()), parent_node); } } } - if count != 1 { - self.push_op(OpCode::OpInterpolate(Count(count)), parent_node); + if parts.len() != 1 { + self.push_op(OpCode::OpInterpolate(Count(parts.len())), parent_node); } } |