tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [2/5] tinkerpop git commit: fixes traversal
Date Wed, 03 Oct 2018 10:13:17 GMT
fixes traversal


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

Branch: refs/heads/master
Commit: b34bf4da9bf4829d6474ccdb9397a30b705bd01d
Parents: 0e34073
Author: Otavio Santana <otaviopolianasantana@gmail.com>
Authored: Tue Sep 25 15:57:52 2018 -0300
Committer: Otavio Santana <otaviopolianasantana@gmail.com>
Committed: Tue Sep 25 15:57:52 2018 -0300

----------------------------------------------------------------------
 .../traversal/dsl/graph/GraphTraversal.java     | 37 ++++++++++++++------
 1 file changed, 27 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/b34bf4da/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
index 5ba7823..ba09a7c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
@@ -1480,22 +1480,39 @@ public interface GraphTraversal<S, E> extends Traversal<S,
E> {
      * @since 3.2.2
      */
     public default GraphTraversal<S, E> hasId(final Object id, final Object... otherIds)
{
-        if (id instanceof P)
+        if (id instanceof P) {
             return this.hasId((P) id);
+        }
         else {
-            final List<Object> ids = new ArrayList<>();
+            Object[] ids;
             if (id instanceof Object[]) {
-                Collections.addAll(ids, (Object[]) id);
-            } else
-                ids.add(id);
+                ids = (Object[]) id;
+            } else {
+                ids = new Object[] {id};
+            }
+            int size = ids.length;
+            int capacity = size;
             for (final Object i : otherIds) {
                 if (i.getClass().isArray()) {
-                    Collections.addAll(ids, (Object[]) i);
-                } else
-                    ids.add(i);
+                    final Object[] tmp = (Object[]) i;
+                    int newLength = size + tmp.length;
+                    if (capacity < newLength) {
+                        ids = Arrays.copyOf(ids, capacity = size + tmp.length);
+                    }
+                    System.arraycopy(tmp, 0, ids, size, tmp.length);
+                    size = newLength;
+                } else {
+                    if (capacity == size) {
+                        ids = Arrays.copyOf(ids, capacity = size * 2);
+                    }
+                    ids[size++] = i;
+                }
+            }
+            if (capacity > size) {
+                ids = Arrays.copyOf(ids, size);
             }
-            this.asAdmin().getBytecode().addStep(Symbols.hasId, ids.toArray());
-            return TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(T.id.getAccessor(),
ids.size() == 1 ? P.eq(ids.get(0)) : P.within(ids)));
+            this.asAdmin().getBytecode().addStep(Symbols.hasId, ids);
+            return TraversalHelper.addHasContainer(this.asAdmin(), new HasContainer(T.id.getAccessor(),
ids.length == 1 ? P.eq(ids[0]) : P.within(ids)));
         }
     }
 


Mime
View raw message