From 05958703410d37f874c4705cabbbba2082c555f7 Mon Sep 17 00:00:00 2001 From: sterni Date: Thu, 15 Sep 2022 17:42:26 +0200 Subject: refactor(tvix/eval): don't move parts Vec in compile_str_parts 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 Reviewed-by: tazjin Tested-by: BuildkiteCI --- tvix/eval/src/compiler/mod.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'tvix/eval/src') diff --git a/tvix/eval/src/compiler/mod.rs b/tvix/eval/src/compiler/mod.rs index f0c9d0dc43..15ff0ea309 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>, ) { - 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); } } -- cgit 1.4.1