Optimize RESTCONF module/node parsing 42/9342/2
authorRobert Varga <rovarga@cisco.com>
Sat, 26 Jul 2014 04:41:44 +0000 (06:41 +0200)
committerRobert Varga <rovarga@cisco.com>
Sat, 26 Jul 2014 15:26:41 +0000 (17:26 +0200)
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 <rovarga@cisco.com>
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java

index 671bd6da8a1dbbb8a6d51cc33c2ac99d52f03101..0a67c84d8b2b04c56a31fa2d7e9dd2e3e8821934 100644 (file)
@@ -86,8 +86,6 @@ public class ControllerContext implements SchemaContextListener {
 
     private static final Splitter SLASH_SPLITTER = Splitter.on('/');
 
 
     private static final Splitter SLASH_SPLITTER = Splitter.on('/');
 
-    private static final Splitter COLON_SPLITTER = Splitter.on(':');
-
     private final BiMap<URI, String> uriToModuleName = HashBiMap.<URI, String> create();
 
     private final Map<String, URI> moduleNameToUri = uriToModuleName.inverse();
     private final BiMap<URI, String> uriToModuleName = HashBiMap.<URI, String> create();
 
     private final Map<String, URI> moduleNameToUri = uriToModuleName.inverse();
@@ -796,24 +794,31 @@ public class ControllerContext implements SchemaContextListener {
     }
 
     private static String toModuleName(final String str) {
     }
 
     private static String toModuleName(final String str) {
-        Preconditions.<String> checkNotNull(str);
-        if (str.indexOf(':') != -1) {
-            final Iterable<String> 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) {
     }
 
     private static String toNodeName(final String str) {
-        if (str.indexOf(':') != -1) {
-            final Iterable<String> 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) {
     }
 
     private QName toQName(final String name) {
@@ -849,7 +854,7 @@ public class ControllerContext implements SchemaContextListener {
         return namespace.isPresent() ? QName.create(namespace.get(), node) : null;
     }
 
         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;
     }
 
         return node instanceof ListSchemaNode || node instanceof ContainerSchemaNode;
     }