mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-24 18:52:58 +03:00
perf: reduce allocations in Boolean's SignExtend impl
Signed-off-by: ljedrz <ljedrz@gmail.com>
This commit is contained in:
parent
78f98f1f26
commit
710bbc6730
@ -16,6 +16,8 @@
|
||||
|
||||
use snarkos_models::gadgets::utilities::boolean::Boolean;
|
||||
|
||||
use std::iter;
|
||||
|
||||
/// Sign extends an array of bits to the desired length.
|
||||
/// Expects least significant bit first
|
||||
pub trait SignExtend
|
||||
@ -30,10 +32,10 @@ impl SignExtend for Boolean {
|
||||
fn sign_extend(bits: &[Boolean], length: usize) -> Vec<Boolean> {
|
||||
let msb = bits.last().expect("empty bit list");
|
||||
let bits_needed = length - bits.len();
|
||||
let mut extension = vec![*msb; bits_needed];
|
||||
|
||||
let mut result = Vec::from(bits);
|
||||
result.append(&mut extension);
|
||||
let mut result = Vec::with_capacity(length);
|
||||
result.extend_from_slice(bits);
|
||||
result.extend(iter::repeat(*msb).take(bits_needed));
|
||||
|
||||
result
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user