From 72382540b7780b0083e05f148300dd1f3f47b687 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 26 Jul 2014 06:41:44 +0200 Subject: [PATCH] Optimize RESTCONF module/node parsing Profiling has shown that the current implementations are still not upto par with what they should be: 189 invocations of the two consumed 64ms, with most of the time being spent splitting and iterating. Given that the parsing operation is really simple, we can do much better using String.indexOf() and String.substring(). Change-Id: I06ef0403edb2c8d12cbbc3c7909091e9efc5138e Signed-off-by: Robert Varga --- .../sal/restconf/impl/ControllerContext.java | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java index 671bd6da8a..0a67c84d8b 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java @@ -86,8 +86,6 @@ public class ControllerContext implements SchemaContextListener { private static final Splitter SLASH_SPLITTER = Splitter.on('/'); - private static final Splitter COLON_SPLITTER = Splitter.on(':'); - private final BiMap uriToModuleName = HashBiMap. create(); private final Map moduleNameToUri = uriToModuleName.inverse(); @@ -796,24 +794,31 @@ public class ControllerContext implements SchemaContextListener { } private static String toModuleName(final String str) { - Preconditions. checkNotNull(str); - if (str.indexOf(':') != -1) { - final Iterable args = COLON_SPLITTER.split(str); - if (Iterables.size(args) == 2) { - return args.iterator().next(); - } + final int idx = str.indexOf(':'); + if (idx == -1) { + return null; } - return null; + + // Make sure there is only one occurrence + if (str.indexOf(':', idx + 1) != -1) { + return null; + } + + return str.substring(0, idx); } private static String toNodeName(final String str) { - if (str.indexOf(':') != -1) { - final Iterable args = COLON_SPLITTER.split(str); - if (Iterables.size(args) == 2) { - return Iterables.get(args, 1); - } + final int idx = str.indexOf(':'); + if (idx == -1) { + return str; } - return str; + + // Make sure there is only one occurrence + if (str.indexOf(':', idx + 1) != -1) { + return str; + } + + return str.substring(idx + 1); } private QName toQName(final String name) { @@ -849,7 +854,7 @@ public class ControllerContext implements SchemaContextListener { return namespace.isPresent() ? QName.create(namespace.get(), node) : null; } - private boolean isListOrContainer(final DataSchemaNode node) { + private static boolean isListOrContainer(final DataSchemaNode node) { return node instanceof ListSchemaNode || node instanceof ContainerSchemaNode; } -- 2.36.6