Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1254 a8bcd7dc1 -> a4e89c082


optimized Path.equals() in both ImmutablePath and MutablePath.. Lots of 
unnecessary object creation removed. Now that path equality is likely with 
bulking due to Path retraction, having equals() fast and clean is important.


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

Branch: refs/heads/TINKERPOP-1254
Commit: a4e89c082fc5b719669330811e714db7bfbf67e9
Parents: a8bcd7d
Author: Marko A. Rodriguez <okramma...@gmail.com>
Authored: Mon Jul 11 13:33:00 2016 -0600
Committer: Marko A. Rodriguez <okramma...@gmail.com>
Committed: Mon Jul 11 13:33:00 2016 -0600

----------------------------------------------------------------------
 .../traversal/step/util/ImmutablePath.java      | 25 +++++++++++++-------
 .../traversal/step/util/MutablePath.java        | 14 ++++++-----
 2 files changed, 25 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a4e89c08/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 fb3155f..feddc59 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
@@ -190,13 +190,23 @@ public class ImmutablePath implements Path, 
ImmutablePathImpl, Serializable, Clo
         if (!(other instanceof Path))
             return false;
         final Path otherPath = (Path) other;
-        if (otherPath.size() != this.size())
+        int size = this.size();
+        if (otherPath.size() != size)
             return false;
-        for (int i = this.size() - 1; i >= 0; i--) {
-            if (!this.get(i).equals(otherPath.get(i)))
-                return false;
-            if (!this.labels().get(i).equals(otherPath.labels().get(i)))
-                return false;
+        if (size > 0) {
+            ImmutablePath currentPathSection = this;
+            final List<Object> otherObjects = otherPath.objects();
+            final List<Set<String>> otherLabels = otherPath.labels();
+            for (int i = otherLabels.size() - 1; i >= 0; i--) {
+                if 
(!currentPathSection.currentObject.equals(otherObjects.get(i)))
+                    return false;
+                if 
(!currentPathSection.currentLabels.equals(otherLabels.get(i)))
+                    return false;
+                if (currentPathSection.previousPath instanceof TailPath)
+                    break;
+                else
+                    currentPathSection = (ImmutablePath) 
currentPathSection.previousPath;
+            }
         }
         return true;
     }
@@ -221,9 +231,8 @@ public class ImmutablePath implements Path, 
ImmutablePathImpl, Serializable, Clo
 
         @Override
         public Path extend(final Set<String> labels) {
-            if (labels.size() == 0) {
+            if (labels.isEmpty())
                 return this;
-            }
             throw new UnsupportedOperationException("A head path can not have 
labels added to it");
         }
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/a4e89c08/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java
index f97879f..e9fc093 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java
@@ -80,9 +80,8 @@ public class MutablePath implements Path, Serializable {
 
     @Override
     public Path extend(final Set<String> labels) {
-        if (labels.size() > 0) {
+        if (!labels.isEmpty())
             this.labels.get(this.labels.size() - 1).addAll(labels);
-        }
         return this;
     }
 
@@ -167,12 +166,15 @@ public class MutablePath implements Path, Serializable {
         if (!(other instanceof Path))
             return false;
         final Path otherPath = (Path) other;
-        if (otherPath.size() != this.size())
+        if (otherPath.size() != this.objects.size())
             return false;
-        for (int i = this.size() - 1; i >= 0; i--) {
-            if (!this.objects.get(i).equals(otherPath.get(i)))
+
+        final List<Object> otherPathObjects = otherPath.objects();
+        final List<Set<String>> otherPathLabels = otherPath.labels();
+        for (int i = this.objects.size() - 1; i >= 0; i--) {
+            if (!this.objects.get(i).equals(otherPathObjects.get(i)))
                 return false;
-            if (!this.labels.get(i).equals(otherPath.labels().get(i)))
+            if (!this.labels.get(i).equals(otherPathLabels.get(i)))
                 return false;
         }
         return true;

Reply via email to