Lower SchemaPath#getPath() memory overhead
[yangtools.git] / yang / yang-model-api / src / main / java / org / opendaylight / yangtools / yang / model / api / SchemaPath.java
index 9601a3910fa265b26d2023b3010981107b335242..fd4466d0343c7ac21c6634c8e896db72441c70ad 100644 (file)
@@ -12,7 +12,9 @@ import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
 import com.google.common.collect.UnmodifiableIterator;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
@@ -121,7 +123,11 @@ public abstract class SchemaPath implements Immutable {
     private ImmutableList<QName> getLegacyPath() {
         ImmutableList<QName> ret = legacyPath;
         if (ret == null) {
-            ret = ImmutableList.copyOf(getPathTowardsRoot()).reverse();
+            final List<QName> tmp = new ArrayList<>();
+            for (QName qname : getPathTowardsRoot()) {
+                tmp.add(qname);
+            }
+            ret = ImmutableList.copyOf(Lists.reverse(tmp));
             LEGACYPATH_UPDATER.lazySet(this, ret);
         }