mirror of
https://github.com/bisq-network/bisq.git
synced 2025-01-19 05:44:05 +01:00
Simplify & optimise BurningManAccountingStore.purgeLastTenBlocks
Remove the last 10 blocks one-by-one from the end of the internal linked list of blocks, instead of rebuilding a truncated list from scratch. (This all takes place within a write-lock anyway, so it's atomic.)
This commit is contained in:
parent
02ee5bc6ea
commit
0214566619
@ -74,7 +74,9 @@ public class BurningManAccountingStore implements PersistableEnvelope {
|
||||
Lock writeLock = readWriteLock.writeLock();
|
||||
writeLock.lock();
|
||||
try {
|
||||
purgeLast10Blocks();
|
||||
for (int i = 0; i < 10 && !blocks.isEmpty(); i++) {
|
||||
blocks.removeLast();
|
||||
}
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
@ -147,17 +149,6 @@ public class BurningManAccountingStore implements PersistableEnvelope {
|
||||
}
|
||||
}
|
||||
|
||||
private void purgeLast10Blocks() {
|
||||
if (blocks.size() <= 10) {
|
||||
blocks.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
List<AccountingBlock> purged = new ArrayList<>(blocks.subList(0, blocks.size() - 10));
|
||||
blocks.clear();
|
||||
blocks.addAll(purged);
|
||||
}
|
||||
|
||||
public Message toProtoMessage() {
|
||||
List<AccountingBlock> blocksCopy;
|
||||
Lock readLock = readWriteLock.readLock();
|
||||
|
Loading…
Reference in New Issue
Block a user