Improve DataNormalizer performance 49/100249/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 24 Mar 2022 20:36:43 +0000 (21:36 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 24 Mar 2022 20:38:16 +0000 (21:38 +0100)
We are using ImmutableList.Builder and build() at each step to pass
arguments down to checkArgument(). That's wasteful, let's rather pay
the cost of a single ImmutableList.copyOf() -- which breaks even at
three path arguments.

Change-Id: I586761f5e8f8e39f1be3c85bc5e9181c1681e6fd
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/DataNormalizer.java

index 753b5154773bec73d45c4446b4773c59852bbdc1..81224b5f36827af0f72d987b5644520c887b8976 100644 (file)
@@ -10,7 +10,9 @@ package org.opendaylight.netconf.sal.restconf.impl;
 import static com.google.common.base.Preconditions.checkArgument;
 
 import com.google.common.collect.ImmutableList;
+import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
@@ -23,7 +25,7 @@ class DataNormalizer {
     }
 
     YangInstanceIdentifier toNormalized(final YangInstanceIdentifier legacy) {
-        ImmutableList.Builder<PathArgument> normalizedArgs = ImmutableList.builder();
+        List<PathArgument> normalizedArgs = new ArrayList<>();
 
         DataNormalizationOperation<?> currentOp = operation;
         Iterator<PathArgument> arguments = legacy.getPathArguments().iterator();
@@ -34,7 +36,7 @@ class DataNormalizer {
                 currentOp = currentOp.getChild(legacyArg);
                 checkArgument(currentOp != null,
                         "Legacy Instance Identifier %s is not correct. Normalized Instance Identifier so far %s",
-                        legacy, normalizedArgs.build());
+                        legacy, normalizedArgs);
                 while (currentOp.isMixin()) {
                     normalizedArgs.add(currentOp.getIdentifier());
                     currentOp = currentOp.getChild(legacyArg.getNodeType());
@@ -42,10 +44,10 @@ class DataNormalizer {
                 normalizedArgs.add(legacyArg);
             }
         } catch (DataNormalizationException e) {
-            throw new IllegalArgumentException(String.format("Failed to normalize path %s", legacy), e);
+            throw new IllegalArgumentException("Failed to normalize path " + legacy, e);
         }
 
-        return YangInstanceIdentifier.create(normalizedArgs.build());
+        return YangInstanceIdentifier.create(normalizedArgs);
     }
 
     DataNormalizationOperation<?> getOperation(final YangInstanceIdentifier legacy)