ImmutablePath.Head can be retrated -- it simply returns itself as it has no 
data. Removed a System.out.println I left in PrunePathStrategyTest. Tweaking 
MatchStep slightly around tags -- found a few archaic lines that were pointless 
wastes of memory/time.


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

Branch: refs/heads/TINKERPOP-1278
Commit: aa6059a1e3ea9ab627f1868846c591cbce713e0e
Parents: ba37407
Author: Marko A. Rodriguez <okramma...@gmail.com>
Authored: Fri Jul 8 14:19:21 2016 -0600
Committer: Marko A. Rodriguez <okramma...@gmail.com>
Committed: Fri Jul 8 14:19:21 2016 -0600

----------------------------------------------------------------------
 .../process/traversal/step/map/MatchStep.java   | 25 +++++++++-----------
 .../traversal/step/util/ImmutablePath.java      |  2 +-
 .../optimization/PrunePathStrategyTest.java     |  1 -
 3 files changed, 12 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/aa6059a1/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStep.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStep.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStep.java
index 0a6d59b..d199c7e 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStep.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStep.java
@@ -330,9 +330,11 @@ public final class MatchStep<S, E> extends 
ComputerAwareStep<S, Map<String, E>>
             }
             if (null == traverser) {
                 traverser = this.starts.next();
-                if (!this.hasPathLabel(traverser.path(), 
this.matchStartLabels))
-                    
traverser.addLabels(Collections.singleton(this.computedStartLabel)); // if the 
traverser doesn't have a legal start, then provide it the pre-computed one
-                traverser.getTags().add(this.getId()); // so the traverser 
never returns to this branch ever again
+                if (!traverser.getTags().contains(this.getId())) {
+                    traverser.getTags().add(this.getId()); // so the traverser 
never returns to this branch ever again
+                    if (!this.hasPathLabel(traverser.path(), 
this.matchStartLabels))
+                        
traverser.addLabels(Collections.singleton(this.computedStartLabel)); // if the 
traverser doesn't have a legal start, then provide it the pre-computed one
+                }
             }
             ///
             if (!this.isDuplicate(traverser)) {
@@ -362,9 +364,11 @@ public final class MatchStep<S, E> extends 
ComputerAwareStep<S, Map<String, E>>
                 this.initializeMatchAlgorithm(TraversalEngine.Type.COMPUTER);
             }
             final Traverser.Admin traverser = this.starts.next();
-            if (!this.hasPathLabel(traverser.path(), this.matchStartLabels))
-                
traverser.addLabels(Collections.singleton(this.computedStartLabel)); // if the 
traverser doesn't have a legal start, then provide it the pre-computed one
-            traverser.getTags().add(this.getId()); // so the traverser never 
returns to this branch ever again
+            if (!traverser.getTags().contains(this.getId())) {
+                traverser.getTags().add(this.getId()); // so the traverser 
never returns to this branch ever again
+                if (!this.hasPathLabel(traverser.path(), 
this.matchStartLabels))
+                    
traverser.addLabels(Collections.singleton(this.computedStartLabel)); // if the 
traverser doesn't have a legal start, then provide it the pre-computed one
+            }
             ///
             if (!this.isDuplicate(traverser)) {
                 if (hasMatched(this.connective, traverser)) {
@@ -454,7 +458,6 @@ public final class MatchStep<S, E> extends 
ComputerAwareStep<S, Map<String, E>>
         @Override
         protected Traverser.Admin<Object> processNextStart() throws 
NoSuchElementException {
             final Traverser.Admin<Object> traverser = this.starts.next();
-            traverser.addLabels(Collections.singleton(this.getId()));
             ((MatchStep<?, ?>) 
this.getTraversal().getParent()).getMatchAlgorithm().recordStart(traverser, 
this.getTraversal());
             // TODO: sideEffect check?
             return null == this.selectKey ? traverser : 
traverser.split(traverser.path().get(Pop.last, this.selectKey), this);
@@ -574,13 +577,7 @@ public final class MatchStep<S, E> extends 
ComputerAwareStep<S, Map<String, E>>
         }
 
         public static boolean hasExecutedTraversal(final 
Traverser.Admin<Object> traverser, final Traversal.Admin<Object, Object> 
traversal) {
-            final boolean hasExecuted = 
traverser.getTags().contains(traversal.getStartStep().getId());
-            if (hasExecuted) {
-                // This traverser has finished this traversal so it is safe to 
drop the tag label.
-                String traversalId = traversal.getStartStep().getId();
-                traverser.dropLabels(Collections.singleton(traversalId));
-            }
-            return hasExecuted;
+            return 
traverser.getTags().contains(traversal.getStartStep().getId());
         }
 
         public static TraversalType getTraversalType(final 
Traversal.Admin<Object, Object> traversal) {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/aa6059a1/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 68ee2b9..b71c56e 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
@@ -321,7 +321,7 @@ public class ImmutablePath implements Path, 
ImmutablePathImpl, Serializable, Clo
 
         @Override
         public Path retract(final Set<String> labels) {
-            throw new UnsupportedOperationException("A head path can not have 
labels added to it");
+            return this;
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/aa6059a1/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PrunePathStrategyTest.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PrunePathStrategyTest.java
 
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PrunePathStrategyTest.java
index b064b47..c8ef0b7 100644
--- 
a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PrunePathStrategyTest.java
+++ 
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PrunePathStrategyTest.java
@@ -67,7 +67,6 @@ public class PrunePathStrategyTest {
         for (final TraversalStrategies currentStrategies : this.strategies) {
             final Traversal.Admin<?, ?> currentTraversal = 
this.traversal.clone();
             currentTraversal.setStrategies(currentStrategies);
-            System.out.println(currentStrategies);
             currentTraversal.applyStrategies();
             final List<Object> keepLabels = getKeepLabels(currentTraversal);
             assertEquals(this.labels, keepLabels);

Reply via email to