File tree Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -3908,19 +3908,22 @@ impl AccountsDb {
3908
3908
// stable sort because we want the most recent only
3909
3909
accounts.sort_by(|a, b| a.pubkey().cmp(b.pubkey()));
3910
3910
if accounts.len() > 1 {
3911
- let mut i = 0;
3912
- // iterate 0..1 less than end
3913
- while i < accounts.len() - 1 {
3914
- let current = accounts[i];
3915
- let next = accounts[i + 1];
3916
- if current.pubkey() == next.pubkey() {
3917
- // remove the first duplicate
3918
- accounts.remove(i);
3919
- // do not advance i, we just removed an element at i
3920
- continue;
3911
+ let mut last = 0;
3912
+ let mut curr = 1;
3913
+
3914
+ loop {
3915
+ if accounts[curr].pubkey() == accounts[last].pubkey() {
3916
+ accounts[last] = accounts[curr];
3917
+ } else {
3918
+ last += 1;
3919
+ accounts[last] = accounts[curr];
3920
+ }
3921
+ curr += 1;
3922
+ if curr == accounts.len() {
3923
+ break;
3921
3924
}
3922
- i += 1;
3923
3925
}
3926
+ accounts.truncate(last + 1);
3924
3927
}
3925
3928
}
3926
3929
You can’t perform that action at this time.
0 commit comments