about summary refs log tree commit diff
path: root/tvix/eval
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-30T16·52+0300
committertazjin <tazjin@tvl.su>2022-09-07T15·25+0000
commit79a2ba51752da188323ecf53d7b55fc5bedc003a (patch)
tree09f331acaba11ab1974657448c4a2534234beddb /tvix/eval
parenta8b2ba07df0fb9f2fa19ce0f13c5fee9c0356599 (diff)
fix(tvix/eval): avoid recomputing width in disassemble_op constantly r/4697
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>
Diffstat (limited to 'tvix/eval')
-rw-r--r--tvix/eval/src/disassembler.rs8
1 files changed, 4 insertions, 4 deletions
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<Stderr>, 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<Stderr>, 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();