mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
[REFACTOR] Inline capability check for ProtectedStorageEntries
Move the capability check inside the stream operation. This should improve performance slightly, but more importantly it makes the two filter functions almost identical so they can be combined.
This commit is contained in:
parent
703a9a0ddd
commit
3aaf8a285e
@ -289,33 +289,19 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
|
||||
int maxEntries,
|
||||
AtomicBoolean outProtectedStorageEntryOutputTruncated,
|
||||
Capabilities peerCapabilities) {
|
||||
Set<ProtectedStorageEntry> filteredDataSet = new HashSet<>();
|
||||
|
||||
AtomicInteger maxSize = new AtomicInteger(maxEntries);
|
||||
Set<P2PDataStorage.ByteArray> excludedKeysAsByteArray = P2PDataStorage.ByteArray.convertBytesSetToByteArraySet(getDataRequest.getExcludedKeys());
|
||||
Set<ProtectedStorageEntry> filteredSet = this.map.entrySet().stream()
|
||||
.filter(e -> !excludedKeysAsByteArray.contains(e.getKey()))
|
||||
.filter(e -> maxSize.decrementAndGet() >= 0)
|
||||
.map(Map.Entry::getValue)
|
||||
.filter(protectedStorageEntry -> shouldTransmitPayloadToPeer(peerCapabilities, protectedStorageEntry.getProtectedStoragePayload()))
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
if (maxSize.get() <= 0)
|
||||
outProtectedStorageEntryOutputTruncated.set(true);
|
||||
|
||||
for (ProtectedStorageEntry protectedStorageEntry : filteredSet) {
|
||||
final ProtectedStoragePayload protectedStoragePayload = protectedStorageEntry.getProtectedStoragePayload();
|
||||
boolean doAdd = false;
|
||||
if (protectedStoragePayload instanceof CapabilityRequiringPayload) {
|
||||
if (shouldTransmitPayloadToPeer(peerCapabilities, protectedStoragePayload))
|
||||
doAdd = true;
|
||||
} else {
|
||||
doAdd = true;
|
||||
}
|
||||
if (doAdd) {
|
||||
filteredDataSet.add(protectedStorageEntry);
|
||||
}
|
||||
}
|
||||
return filteredDataSet;
|
||||
return filteredSet;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user