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 <sternenseemann@systemli.org> Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
This commit is contained in:
		
							parent
							
								
									4eb33e82ff
								
							
						
					
					
						commit
						0595870341
					
				
					 1 changed files with 5 additions and 7 deletions
				
			
		|  | @ -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); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue