lower_level_bloom_indexes use collect instead of for loop

This commit is contained in:
debris 2015-11-28 21:11:10 +01:00
parent a6240c0d30
commit b405c061a1

View File

@ -77,24 +77,15 @@ impl<'a, D> ChainFilter<'a, D> where D: FilterDataSource
/// ///
/// bloom indexes are ordered from lowest to highest /// bloom indexes are ordered from lowest to highest
fn lower_level_bloom_indexes(&self, index: &BloomIndex) -> Vec<BloomIndex> { fn lower_level_bloom_indexes(&self, index: &BloomIndex) -> Vec<BloomIndex> {
let mut indexes: Vec<BloomIndex> = vec![]; // this is the lowest level
// this is the lower level
if index.level == 0 { if index.level == 0 {
return indexes; return vec![];
} }
let new_level = index.level - 1; let new_level = index.level - 1;
let offset = self.index_size * index.index; let offset = self.index_size * index.index;
for i in 0..self.index_size { (0..self.index_size).map(|i| BloomIndex::new(new_level, offset + i)).collect()
indexes.push(BloomIndex {
level: new_level,
index: offset + i,
});
}
indexes
} }
/// return number of levels /// return number of levels
@ -140,7 +131,7 @@ impl<'a, D> ChainFilter<'a, D> where D: FilterDataSource
.map(|off| self.blocks(bloom, from_block, to_block, level - 1, off)) .map(|off| self.blocks(bloom, from_block, to_block, level - 1, off))
// filter existing ones // filter existing ones
.filter_map(|x| x) .filter_map(|x| x)
// flatten nested structure // flatten nested structures
.flat_map(|v| v) .flat_map(|v| v)
.collect(); .collect();
Some(res) Some(res)