prevent excess allocation with AccountsIndexIterator (#18605) (#18642)

(cherry picked from commit 0bd8710d34)

Co-authored-by: Jeff Washington (jwash) <75863576+jeffwashington@users.noreply.github.com>
This commit is contained in:
mergify[bot]
2021-07-19 20:15:40 +00:00
committed by GitHub
parent 927057df26
commit ea192b3c83

View File

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