add performance optimization when requesting purpose node for deep wallets

This commit is contained in:
Craig Raw 2022-07-14 14:48:05 +02:00
parent 6d0d5b7f62
commit 377843a4a5

View file

@ -205,6 +205,20 @@ public class WalletNode extends Persistable implements Comparable<WalletNode> {
} }
public synchronized Set<WalletNode> fillToIndex(int index) { public synchronized Set<WalletNode> fillToIndex(int index) {
//Optimization to check if child nodes already monotonically increment to the desired index
int indexCheck = 0;
for(WalletNode childNode : getChildren()) {
if(childNode.index == indexCheck) {
indexCheck++;
} else {
break;
}
if(childNode.index == index) {
return Collections.emptySet();
}
}
Set<WalletNode> newNodes = new TreeSet<>(); Set<WalletNode> newNodes = new TreeSet<>();
for(int i = 0; i <= index; i++) { for(int i = 0; i <= index; i++) {
WalletNode node = new WalletNode(wallet, getKeyPurpose(), i); WalletNode node = new WalletNode(wallet, getKeyPurpose(), i);