From: Robert Varga Date: Thu, 16 Jan 2014 09:23:19 +0000 (+0100) Subject: Do not instantiate constant lists on each message X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~59^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=8c11d12db26f05afafe154fd1feed6c88fb04fa0 Do not instantiate constant lists on each message These really are constats, so treat them as such Change-Id: I850095e2e0aaab19f69b7d8bfc6ea734d1bd4877 Signed-off-by: Robert Varga --- diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/messages/NetconfMessageFactory.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/messages/NetconfMessageFactory.java index 526708ab58..9097da4d91 100644 --- a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/messages/NetconfMessageFactory.java +++ b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/messages/NetconfMessageFactory.java @@ -29,7 +29,7 @@ import org.xml.sax.SAXException; import com.google.common.base.Charsets; import com.google.common.base.Optional; -import com.google.common.collect.Lists; +import com.google.common.collect.ImmutableList; /** * NetconfMessageFactory for (de)serializing DOM documents. @@ -37,6 +37,10 @@ import com.google.common.collect.Lists; public final class NetconfMessageFactory implements ProtocolMessageFactory { private static final Logger logger = LoggerFactory.getLogger(NetconfMessageFactory.class); + private static final List POSSIBLE_STARTS = ImmutableList.of( + "[".getBytes(Charsets.UTF_8), "\r\n[".getBytes(Charsets.UTF_8), "\n[".getBytes(Charsets.UTF_8)); + private static final List POSSIBLE_ENDS = ImmutableList.of( + "]\n".getBytes(Charsets.UTF_8), "]\r\n".getBytes(Charsets.UTF_8)); private final Optional clientId; @@ -74,8 +78,8 @@ public final class NetconfMessageFactory implements ProtocolMessageFactory possibleStarts = Lists.newArrayList("[", "\r\n[", "\n["); - for (String possibleStart : possibleStarts) { + for (byte[] possibleStart : POSSIBLE_STARTS) { int i = 0; - for (byte b : possibleStart.getBytes(Charsets.UTF_8)) { - if(bytes[i]!=b) + for (byte b : possibleStart) { + if(bytes[i] != b) break; return true;