From: Robert Varga Date: Tue, 4 Jun 2019 17:54:22 +0000 (+0200) Subject: Optimize readQNameSet() X-Git-Tag: release/neon-sr2~32 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;ds=sidebyside;h=refs%2Fchanges%2F09%2F82409%2F1;p=controller.git Optimize readQNameSet() We are providing a bad hint to HashSet, as we are not taking into consideration its load factor. Use utility methods from Guava to get a properly-sized set. JIRA: CONTROLLER-1898 Change-Id: I568be3040b924a8ed77aa0224ab45673104c4664 Signed-off-by: Robert Varga (cherry picked from commit 11666b718f70c7846cd64ebf949a4e91d84e0e65) --- diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/LithiumNormalizedNodeInputStreamReader.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/LithiumNormalizedNodeInputStreamReader.java index 6303420b3f..573e4ed2fa 100755 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/LithiumNormalizedNodeInputStreamReader.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/datastore/node/utils/stream/LithiumNormalizedNodeInputStreamReader.java @@ -12,6 +12,7 @@ import static java.util.Objects.requireNonNull; import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList.Builder; +import com.google.common.collect.Sets; import java.io.DataInput; import java.io.IOException; import java.io.StringReader; @@ -241,8 +242,8 @@ class LithiumNormalizedNodeInputStreamReader extends ForwardingDataInput impleme private Set readQNameSet() throws IOException { // Read the children count - int count = input.readInt(); - Set children = new HashSet<>(count); + final int count = input.readInt(); + final Set children = Sets.newHashSetWithExpectedSize(count); for (int i = 0; i < count; i++) { children.add(readQName()); }