Skip to content

Commit 4c4028a

Browse files
authored
math.big: refactor add_digit_array() (#25138)
1 parent b99c382 commit 4c4028a

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎vlib/math/big/array_ops.v‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@ fn add_digit_array(operand_a []u64, operand_b []u64, mut sum []u64) {
3434
for index in 0 .. operand_b.len {
3535
sum[index] = operand_b[index]
3636
}
37+
shrink_tail_zeros(mut sum)
38+
return
3739
}
3840
if operand_b.len == 0 {
3941
for index in 0 .. operand_a.len {
4042
sum[index] = operand_a[index]
4143
}
44+
shrink_tail_zeros(mut sum)
45+
return
4246
}
4347

4448
// First pass intersects with both operands
@@ -62,11 +66,8 @@ fn add_digit_array(operand_a []u64, operand_b []u64, mut sum []u64) {
6266
carry = u64(partial >> digit_bits)
6367
}
6468

65-
if carry == 0 {
66-
sum.delete_last()
67-
} else {
68-
sum[larger_limit] = carry
69-
}
69+
sum[larger_limit] = carry
70+
shrink_tail_zeros(mut sum)
7071
}
7172

7273
// Subtracts operand_b from operand_a and stores the difference in storage.

0 commit comments

Comments
 (0)