Use vec![elt; n] where possible
The common pattern `iter::repeat(elt).take(n).collect::<Vec<_>>()` is exactly equivalent to `vec![elt; n]`, do this replacement in the whole tree. (Actually, vec![] is smart enough to only call clone n - 1 times, while the former solution would call clone n times, and this fact is virtually irrelevant in practice.)
This commit is contained in:
parent
5b6a464358
commit
836f32e769
31 changed files with 61 additions and 91 deletions
|
|
@ -8,8 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::iter;
|
||||
|
||||
/// A very simple BitVector type.
|
||||
pub struct BitVector {
|
||||
data: Vec<u64>
|
||||
|
|
@ -18,7 +16,7 @@ pub struct BitVector {
|
|||
impl BitVector {
|
||||
pub fn new(num_bits: usize) -> BitVector {
|
||||
let num_words = (num_bits + 63) / 64;
|
||||
BitVector { data: iter::repeat(0).take(num_words).collect() }
|
||||
BitVector { data: vec![0; num_words] }
|
||||
}
|
||||
|
||||
fn word_mask(&self, bit: usize) -> (usize, u64) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue