Overrode Path.isSimple() default impl for ImmutablePath that doesn't create so many objects.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/3896a981 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/3896a981 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/3896a981 Branch: refs/heads/tp32 Commit: 3896a981fdfced7b19a830738b2f3ef51f82672a Parents: cd00099 Author: Marko A. Rodriguez <okramma...@gmail.com> Authored: Tue Nov 1 07:19:54 2016 -0600 Committer: Marko A. Rodriguez <okramma...@gmail.com> Committed: Tue Nov 1 07:19:54 2016 -0600 ---------------------------------------------------------------------- .../traversal/step/util/ImmutablePath.java | 21 ++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3896a981/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java ---------------------------------------------------------------------- diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java index 4104da7..8afa91c 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java @@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Pop; import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -112,8 +113,8 @@ public class ImmutablePath implements Path, Serializable, Cloneable { public <A> A get(final int index) { int counter = this.size(); ImmutablePath currentPath = this; - while(true) { - if(index == --counter) + while (true) { + if (index == --counter) return (A) currentPath.currentObject; currentPath = currentPath.previousPath; } @@ -265,4 +266,20 @@ public class ImmutablePath implements Path, Serializable, Cloneable { } return true; } + + @Override + public boolean isSimple() { + final Set<Object> objects = new HashSet<>(); + ImmutablePath currentPath = this; + while (true) { + if (currentPath.isTail()) + return true; + else if (objects.contains(currentPath.currentObject)) + return false; + else { + objects.add(currentPath.currentObject); + currentPath = currentPath.previousPath; + } + } + } }