You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2017/04/06 11:33:49 UTC

[22/50] tinkerpop git commit: removed a repeated recurssion in PathRetractionStrategy using the MARKER model of strategies.

removed a repeated recurssion in PathRetractionStrategy using the MARKER model of strategies.


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

Branch: refs/heads/TINKERPOP-1443
Commit: 8e90349a43c843e44b53b87aea7d7c1d9b0ccee7
Parents: acc8d73
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Mar 28 07:46:31 2017 -0600
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Mar 29 11:22:58 2017 -0400

----------------------------------------------------------------------
 .../optimization/PathRetractionStrategy.java    | 26 +++++++++-----------
 .../StandardVerificationStrategy.java           |  3 ++-
 2 files changed, 13 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8e90349a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java
index 10e2372..304161e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java
@@ -58,7 +58,9 @@ public final class PathRetractionStrategy extends AbstractTraversalStrategy<Trav
     private static final PathRetractionStrategy INSTANCE = new PathRetractionStrategy(MAX_BARRIER_SIZE);
     // these strategies do strong rewrites involving path labeling and thus, should run prior to PathRetractionStrategy
     private static final Set<Class<? extends OptimizationStrategy>> PRIORS = new HashSet<>(Arrays.asList(
-            RepeatUnrollStrategy.class, MatchPredicateStrategy.class, PathProcessorStrategy.class));
+            RepeatUnrollStrategy.class,
+            MatchPredicateStrategy.class,
+            PathProcessorStrategy.class));
     private static final String MARKER = Graph.Hidden.hide("gremlin.pathRetraction");
 
     private final int standardBarrierSize;
@@ -76,9 +78,11 @@ public final class PathRetractionStrategy extends AbstractTraversalStrategy<Trav
         // do not apply this strategy if there are lambdas as you can't introspect to know what path information the lambdas are using
         // do not apply this strategy if a PATH requirement step is being used (in the future, we can do PATH requirement lookhead to be more intelligent about its usage)
         // do not apply this strategy if a VertexProgramStep is present with LABELED_PATH requirements
-        if ((traversal.getParent() instanceof EmptyStep || traversal.getParent() instanceof VertexProgramStep) &&
+        if (traversal.getParent() instanceof EmptyStep &&
                 TraversalHelper.anyStepRecursively(step -> step instanceof LambdaHolder ||
-                                                   step.getRequirements().contains(TraverserRequirement.PATH),traversal)) {
+                        step.getRequirements().contains(TraverserRequirement.PATH) ||
+                        (step instanceof VertexProgramStep &&
+                                step.getRequirements().contains(TraverserRequirement.LABELED_PATH)), traversal)) {
             TraversalHelper.applyTraversalRecursively(t -> t.getEndStep().addLabel(MARKER), traversal);
         }
 
@@ -87,11 +91,6 @@ public final class PathRetractionStrategy extends AbstractTraversalStrategy<Trav
             return;
         }
 
-        if (TraversalHelper.anyStepRecursively(step -> step instanceof VertexProgramStep && step.getRequirements().contains(TraverserRequirement.LABELED_PATH),
-                TraversalHelper.getRootTraversal(traversal))) {
-            return;
-        }
-
         final boolean onGraphComputer = TraversalHelper.onGraphComputer(traversal);
         final Set<String> foundLabels = new HashSet<>();
         final Set<String> keepLabels = new HashSet<>();
@@ -223,9 +222,8 @@ public final class PathRetractionStrategy extends AbstractTraversalStrategy<Trav
             // if there is one more RepeatSteps in this traversal's lineage, preserve keep labels
             if (currentStep instanceof PathProcessor) {
                 ((PathProcessor) currentStep).getKeepLabels().addAll(keeperTrail);
-                if (hasRepeat) {
+                if (hasRepeat)
                     ((PathProcessor) currentStep).getKeepLabels().addAll(keepLabels);
-                }
             }
         }
     }
@@ -238,18 +236,16 @@ public final class PathRetractionStrategy extends AbstractTraversalStrategy<Trav
 
     private void addLabels(final Traversal.Admin traversal, final Set<String> keepLabels) {
         for (final Object s : traversal.getSteps()) {
-            if (s instanceof PathProcessor) {
+            if (s instanceof PathProcessor)
                 addLabels((PathProcessor) s, keepLabels);
-            }
         }
     }
 
     private void addLabels(final PathProcessor s, final Set<String> keepLabels) {
-        if (s.getKeepLabels() == null) {
+        if (null == s.getKeepLabels())
             s.setKeepLabels(new HashSet<>(keepLabels));
-        } else {
+        else
             s.getKeepLabels().addAll(new HashSet<>(keepLabels));
-        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/8e90349a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java
index aed5372..cad3b8e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java
@@ -33,6 +33,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Set;
 
 /**
@@ -54,7 +55,7 @@ public final class StandardVerificationStrategy extends AbstractTraversalStrateg
         }
 
         for (final Step<?, ?> step : traversal.getSteps()) {
-            for (String label : step.getLabels()) {
+            for (String label : new HashSet<>(step.getLabels())) {
                 if (Graph.Hidden.isHidden(label))
                     step.removeLabel(label);
             }