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 2018/04/18 22:51:02 UTC

[2/3] tinkerpop git commit: Move validation into set() method to avoid double loop.

Move validation into set() method to avoid double loop.

Parameters tends to be a hotspot in traversal construction. This doesn't amount to much in terms of performance overall for most traversals, but since the validation code isn't being used anywhere else there's not much value in having it isolated anyway. Better to just kill the double loop. CTR


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

Branch: refs/heads/tp33
Commit: 4dcee1ad22bfe5c7597feebbbcb74577e5f8d7ca
Parents: 430c97d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Apr 18 17:43:10 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Apr 18 17:43:10 2018 -0400

----------------------------------------------------------------------
 .../process/traversal/step/util/Parameters.java     | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4dcee1ad/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/Parameters.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/Parameters.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/Parameters.java
index 5cb6001..7fae30a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/Parameters.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/Parameters.java
@@ -171,8 +171,13 @@ public final class Parameters implements Cloneable, Serializable {
      * Set parameters given key/value pairs.
      */
     public void set(final TraversalParent parent, final Object... keyValues) {
-        Parameters.legalPropertyKeyValueArray(keyValues);
+        if (keyValues.length % 2 != 0)
+            throw Element.Exceptions.providedKeyValuesMustBeAMultipleOfTwo();
+
         for (int i = 0; i < keyValues.length; i = i + 2) {
+            if (!(keyValues[i] instanceof String) && !(keyValues[i] instanceof T) && !(keyValues[i] instanceof Traversal))
+                throw new IllegalArgumentException("The provided key/value array must have a String, T, or Traversal on even array indices");
+
             if (keyValues[i + 1] != null) {
                 // track the list of traversals that are present so that elsewhere in Parameters there is no need
                 // to iterate all values to not find any. also grab available labels in traversal values
@@ -253,15 +258,6 @@ public final class Parameters implements Cloneable, Serializable {
         return this.parameters.toString();
     }
 
-    private static void legalPropertyKeyValueArray(final Object... propertyKeyValues) throws IllegalArgumentException {
-        if (propertyKeyValues.length % 2 != 0)
-            throw Element.Exceptions.providedKeyValuesMustBeAMultipleOfTwo();
-        for (int i = 0; i < propertyKeyValues.length; i = i + 2) {
-            if (!(propertyKeyValues[i] instanceof String) && !(propertyKeyValues[i] instanceof T) && !(propertyKeyValues[i] instanceof Traversal))
-                throw new IllegalArgumentException("The provided key/value array must have a String, T, or Traversal on even array indices");
-        }
-    }
-
     private void addTraversal(final Traversal.Admin t) {
         this.traversals.add(t);
         for (final Object ss : t.getSteps()) {