From 79a2ba51752da188323ecf53d7b55fc5bedc003a Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 30 Aug 2022 19:52:58 +0300 Subject: fix(tvix/eval): avoid recomputing width in disassemble_op constantly As noticed by sterni in cl/6195 Change-Id: Ie9c1e80e2e709284fa8412334af9188d999f64dc Reviewed-on: https://cl.tvl.fyi/c/depot/+/6361 Tested-by: BuildkiteCI Reviewed-by: sterni --- tvix/eval/src/disassembler.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tvix/eval') diff --git a/tvix/eval/src/disassembler.rs b/tvix/eval/src/disassembler.rs index e5f6df525ad4..bc5a64fe65e8 100644 --- a/tvix/eval/src/disassembler.rs +++ b/tvix/eval/src/disassembler.rs @@ -37,9 +37,8 @@ impl Drop for Tracer { } } -fn disassemble_op(tw: &mut TabWriter, chunk: &Chunk, offset: usize) { - let code_width = format!("{}", chunk.code.len()).len(); - write!(tw, "{:0width$}\t ", width = code_width).ok(); +fn disassemble_op(tw: &mut TabWriter, chunk: &Chunk, width: usize, offset: usize) { + write!(tw, "{:0width$}\t ", width = width).ok(); match chunk.code[offset] { OpCode::OpConstant(idx) => write!(tw, "OpConstant({})\n", chunk.constant(idx)).ok(), @@ -60,8 +59,9 @@ pub fn disassemble_chunk(chunk: &Chunk) { ) .ok(); + let width = format!("{}", chunk.code.len()).len(); for (idx, _) in chunk.code.iter().enumerate() { - disassemble_op(&mut tw, chunk, idx); + disassemble_op(&mut tw, chunk, width, idx); } tw.flush().ok(); -- cgit 1.4.1