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 <sternenseemann@systemli.org>
This commit is contained in:
Vincent Ambo 2022-08-30 19:52:58 +03:00 committed by tazjin
parent a8b2ba07df
commit 79a2ba5175

View file

@ -37,9 +37,8 @@ impl Drop for Tracer {
} }
} }
fn disassemble_op(tw: &mut TabWriter<Stderr>, chunk: &Chunk, offset: usize) { fn disassemble_op(tw: &mut TabWriter<Stderr>, chunk: &Chunk, width: usize, offset: usize) {
let code_width = format!("{}", chunk.code.len()).len(); write!(tw, "{:0width$}\t ", width = width).ok();
write!(tw, "{:0width$}\t ", width = code_width).ok();
match chunk.code[offset] { match chunk.code[offset] {
OpCode::OpConstant(idx) => write!(tw, "OpConstant({})\n", chunk.constant(idx)).ok(), OpCode::OpConstant(idx) => write!(tw, "OpConstant({})\n", chunk.constant(idx)).ok(),
@ -60,8 +59,9 @@ pub fn disassemble_chunk(chunk: &Chunk) {
) )
.ok(); .ok();
let width = format!("{}", chunk.code.len()).len();
for (idx, _) in chunk.code.iter().enumerate() { for (idx, _) in chunk.code.iter().enumerate() {
disassemble_op(&mut tw, chunk, idx); disassemble_op(&mut tw, chunk, width, idx);
} }
tw.flush().ok(); tw.flush().ok();