tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ok...@apache.org
Subject [3/7] tinkerpop git commit: removed more method-based recursions in ImmutablePath and inlined the singleHead() and singleTail() methods as they are no longer interface methods and are only called in one other method.
Date Wed, 02 Nov 2016 20:57:42 GMT
removed more method-based recursions in ImmutablePath and inlined the singleHead() and singleTail()
methods as they are no longer interface methods and are only called in one other method.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/cd000995
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/cd000995
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/cd000995

Branch: refs/heads/tp32
Commit: cd000995d1670170b9b5f3d726f20fb8cf45ffc9
Parents: 3caa5c8
Author: Marko A. Rodriguez <okrammarko@gmail.com>
Authored: Tue Nov 1 07:09:45 2016 -0600
Committer: Marko A. Rodriguez <okrammarko@gmail.com>
Committed: Tue Nov 1 07:09:45 2016 -0600

----------------------------------------------------------------------
 .../traversal/step/util/ImmutablePath.java      | 67 ++++++++++----------
 1 file changed, 34 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cd000995/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 d64cdb4..4104da7 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
@@ -110,31 +110,11 @@ public class ImmutablePath implements Path, Serializable, Cloneable
{
 
     @Override
     public <A> A get(final int index) {
-        return (this.size() - 1) == index ? (A) this.currentObject : this.previousPath.get(index);
-    }
-
-
-    private final <A> A getSingleHead(final String label) {
+        int counter = this.size();
         ImmutablePath currentPath = this;
-        while (true) {
-            if (currentPath.isTail())
-                return null;
-            else if (currentPath.currentLabels.contains(label))
+        while(true) {
+            if(index == --counter)
                 return (A) currentPath.currentObject;
-            else
-                currentPath = currentPath.previousPath;
-        }
-    }
-
-
-    private final <A> A getSingleTail(final String label) {
-        A found = null;
-        ImmutablePath currentPath = this;
-        while (true) {
-            if (currentPath.isTail())
-                return found;
-            else if (currentPath.currentLabels.contains(label))
-                found = (A) currentPath.currentObject;
             currentPath = currentPath.previousPath;
         }
     }
@@ -143,18 +123,39 @@ public class ImmutablePath implements Path, Serializable, Cloneable
{
     public <A> A get(final Pop pop, final String label) {
         if (Pop.all == pop) {
             // Recursively build the list to avoid building objects/labels collections.
-            final List<A> list = null == this.previousPath ? new ArrayList<>()
: this.previousPath.get(Pop.all, label);
-            // Add our object, if our step labels match.
-            if (this.currentLabels.contains(label))
-                list.add((A) currentObject);
+            final List<Object> list = new ArrayList<>();
+            ImmutablePath currentPath = this;
+            while (true) {
+                if (currentPath.isTail())
+                    break;
+                else if (currentPath.currentLabels.contains(label))
+                    list.add(0, currentPath.currentObject);
+                currentPath = currentPath.previousPath;
+            }
             return (A) list;
-        } else {
-            // Delegate to the non-throwing, optimized head/tail calculations.
-            final A single = Pop.first == pop ? this.getSingleTail(label) : this.getSingleHead(label);
-            // Throw if we didn't find the label.
-            if (null == single)
+        } else if (Pop.last == pop) {
+            ImmutablePath currentPath = this;
+            while (true) {
+                if (currentPath.isTail())
+                    throw Path.Exceptions.stepWithProvidedLabelDoesNotExist(label);
+                else if (currentPath.currentLabels.contains(label))
+                    return (A) currentPath.currentObject;
+                else
+                    currentPath = currentPath.previousPath;
+            }
+        } else { // Pop.first
+            A found = null;
+            ImmutablePath currentPath = this;
+            while (true) {
+                if (currentPath.isTail())
+                    break;
+                else if (currentPath.currentLabels.contains(label))
+                    found = (A) currentPath.currentObject;
+                currentPath = currentPath.previousPath;
+            }
+            if (null == found)
                 throw Path.Exceptions.stepWithProvidedLabelDoesNotExist(label);
-            return single;
+            return found;
         }
     }
 


Mime
View raw message