prevent excess allocation with AccountsIndexIterator (#18605)

This commit is contained in:
Jeff Washington (jwash) 2021-07-13 11:11:17 -05:00 committed by GitHub
parent d092fa1f03
commit 0bd8710d34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 13 deletions

View File

@ -566,19 +566,18 @@ impl<'a, T: 'static + Clone> Iterator for AccountsIndexIterator<'a, T> {
return None;
}
let chunk: Vec<(Pubkey, AccountMapEntry<T>)> = self
.account_maps
.iter()
.map(|i| {
i.read()
.unwrap()
.range((self.start_bound, self.end_bound))
.map(|(pubkey, account_map_entry)| (*pubkey, account_map_entry.clone()))
.collect::<Vec<_>>()
})
.flatten()
.take(ITER_BATCH_SIZE)
.collect();
let mut chunk: Vec<(Pubkey, AccountMapEntry<T>)> = Vec::with_capacity(ITER_BATCH_SIZE);
'outer: for i in self.account_maps.iter() {
for (pubkey, account_map_entry) in
i.read().unwrap().range((self.start_bound, self.end_bound))
{
if chunk.len() >= ITER_BATCH_SIZE {
break 'outer;
}
let item = (*pubkey, account_map_entry.clone());
chunk.push(item);
}
}
if chunk.is_empty() {
self.is_finished = true;