From 573918d56dc8842ad7ea725416eec804062968ed Mon Sep 17 00:00:00 2001 From: Philip Craig Date: Fri, 27 Mar 2020 13:49:41 +1000 Subject: [PATCH] write/line: avoid division if minimum instruction length is 1 --- src/write/line.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/write/line.rs b/src/write/line.rs index a06cb180c..bff12e79f 100644 --- a/src/write/line.rs +++ b/src/write/line.rs @@ -467,12 +467,14 @@ impl LineProgram { fn op_advance(&self) -> u64 { debug_assert!(self.row.address_offset >= self.prev_row.address_offset); - debug_assert_eq!( - self.row.address_offset % u64::from(self.line_encoding.minimum_instruction_length), - 0 - ); - let address_advance = (self.row.address_offset - self.prev_row.address_offset) - / u64::from(self.line_encoding.minimum_instruction_length); + let mut address_advance = self.row.address_offset - self.prev_row.address_offset; + if self.line_encoding.minimum_instruction_length != 1 { + debug_assert_eq!( + self.row.address_offset % u64::from(self.line_encoding.minimum_instruction_length), + 0 + ); + address_advance /= u64::from(self.line_encoding.minimum_instruction_length); + } address_advance * u64::from(self.line_encoding.maximum_operations_per_instruction) + self.row.op_index - self.prev_row.op_index