BUG-1270: optimize SchemaPath creation for augmentations 42/9042/1
authorRobert Varga <rovarga@cisco.com>
Tue, 15 Jul 2014 22:15:55 +0000 (00:15 +0200)
committerRobert Varga <rovarga@cisco.com>
Tue, 15 Jul 2014 22:15:55 +0000 (00:15 +0200)
As it turns out, at least in one case we can use
SchemaPath.createChild(), which is much more efficient than the
Iterable-based constructor. Drop a FIXME to investigate whether we can
reuse an existing SchemaPath in the other case.

Change-Id: I1aae1c9855490a21bcda7ffe17d52e081cc7de1d
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserImpl.java

index d80c31bba8ba48f69d13de75a9e800e570e08cf2..25ace683009ac9f49d72e74458b353f1679450f9 100644 (file)
@@ -766,13 +766,11 @@ public final class YangParserImpl implements YangContextParser {
     private void setCorrectAugmentTargetPath(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
             final AugmentationSchemaBuilder augment) {
         ModuleBuilder module = BuilderUtils.getParentModule(augment);
-        Iterable<QName> oldPath = augment.getTargetPath().getPathFromRoot();
-        List<QName> newPath = new ArrayList<>();
+        final SchemaPath newSchemaPath;
 
         Builder parent = augment.getParent();
         if (parent instanceof UsesNodeBuilder) {
             DataNodeContainerBuilder usesParent = ((UsesNodeBuilder) parent).getParent();
-            newPath.addAll(usesParent.getPath().getPath());
 
             QName baseQName = usesParent.getQName();
             final QNameModule qnm;
@@ -786,11 +784,16 @@ public final class YangParserImpl implements YangContextParser {
                 prefix = baseQName.getPrefix();
             }
 
-            for (QName qn : oldPath) {
-                newPath.add(QName.create(qnm, prefix, qn.getLocalName()));
+            SchemaPath s = usesParent.getPath();
+            for (QName qn : augment.getTargetPath().getPathFromRoot()) {
+                s = s.createChild(QName.create(qnm, prefix, qn.getLocalName()));
             }
+
+            newSchemaPath = s;
         } else {
-            for (QName qn : oldPath) {
+            final List<QName> newPath = new ArrayList<>();
+
+            for (QName qn : augment.getTargetPath().getPathFromRoot()) {
                 QNameModule qnm = module.getQNameModule();
                 String localPrefix = qn.getPrefix();
                 if (localPrefix != null && !localPrefix.isEmpty()) {
@@ -803,8 +806,16 @@ public final class YangParserImpl implements YangContextParser {
                 }
                 newPath.add(QName.create(qnm, localPrefix, qn.getLocalName()));
             }
+
+            /*
+             * FIXME: this method of SchemaPath construction is highly ineffective.
+             *        It would be great if we could actually dive into the context,
+             *        find the actual target node and reuse its SchemaPath. Can we
+             *        do that?
+             */
+            newSchemaPath = SchemaPath.create(newPath, true);
         }
-        augment.setTargetNodeSchemaPath(SchemaPath.create(newPath, true));
+        augment.setTargetNodeSchemaPath(newSchemaPath);
 
         for (DataSchemaNodeBuilder childNode : augment.getChildNodeBuilders()) {
             correctPathForAugmentNodes(childNode, augment.getTargetNodeSchemaPath());