use rust's rotate (in place, yay!)
This commit is contained in:
29
src/bank.rs
29
src/bank.rs
@ -434,11 +434,9 @@ impl Bank {
|
|||||||
let entry_count = 2 + self.process_blocks(entries, &mut tail, &mut tail_idx)?;
|
let entry_count = 2 + self.process_blocks(entries, &mut tail, &mut tail_idx)?;
|
||||||
|
|
||||||
// check f we need to rotate tail
|
// check f we need to rotate tail
|
||||||
let tail = if tail.len() == WINDOW_SIZE as usize {
|
if tail.len() == WINDOW_SIZE as usize {
|
||||||
rotate_vector(tail, tail_idx)
|
tail.rotate_left(tail_idx)
|
||||||
} else {
|
}
|
||||||
tail
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok((entry_count, tail))
|
Ok((entry_count, tail))
|
||||||
}
|
}
|
||||||
@ -541,17 +539,6 @@ impl Bank {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rotate_vector<T: Clone>(v: Vec<T>, at: usize) -> Vec<T> {
|
|
||||||
if at != 0 {
|
|
||||||
let mut ret = Vec::with_capacity(v.len());
|
|
||||||
ret.extend_from_slice(&v[at..]);
|
|
||||||
ret.extend_from_slice(&v[0..at]);
|
|
||||||
ret
|
|
||||||
} else {
|
|
||||||
v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -880,14 +867,4 @@ mod tests {
|
|||||||
assert_eq!(bank.get_balance(&mint.pubkey()), 1);
|
assert_eq!(bank.get_balance(&mint.pubkey()), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_rotate_vector() {
|
|
||||||
let expect = vec![1, 2, 3, 4];
|
|
||||||
|
|
||||||
assert_eq!(rotate_vector(vec![4, 1, 2, 3], 1), expect);
|
|
||||||
assert_eq!(rotate_vector(vec![1, 2, 3, 4], 0), expect);
|
|
||||||
assert_eq!(rotate_vector(vec![2, 3, 4, 1], 3), expect);
|
|
||||||
assert_eq!(rotate_vector(vec![3, 4, 1, 2], 2), expect);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user