Use anyMatch to search routerIds 28/77728/5
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 13 Nov 2018 14:40:01 +0000 (15:40 +0100)
committerStephen Kitt <skitt@redhat.com>
Fri, 16 Nov 2018 15:46:42 +0000 (15:46 +0000)
Full materialization is completely unnecessary and very wasteful,
just use anyMatch(), terminating search as soon as a match is
found. This should halve (on average) the memory overhead.

Change-Id: Ibc28ef9666360efa09707f6193178d16f49c8f74
JIRA: NETVIRT-1503
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
neutronvpn/impl/src/main/java/org/opendaylight/netvirt/neutronvpn/NeutronvpnUtils.java

index c365c1ea54f11b8094501a5eb04dae4bb277851d..f6d941eb4c32fa7eaa11701d32d09b6edcddec41 100644 (file)
@@ -300,9 +300,8 @@ public class NeutronvpnUtils {
                         continue;
                     }
                 }
-                List<Uuid> rtrIdsList = routerIdsList.stream().map(routerIds -> routerIds.getRouterId())
-                        .collect(Collectors.toList());
-                if (rtrIdsList.contains(routerId)) {
+                // FIXME: NETVIRT-1503: this check can be replaced by a ReadOnlyTransaction.exists()
+                if (routerIdsList.stream().anyMatch(routerIds -> routerId.equals(routerIds.getRouterId()))) {
                     if (externalVpn) {
                         if (!routerId.equals(vpnMap.getVpnId())) {
                             return vpnMap.getVpnId();