Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id ED578200BB1 for ; Thu, 3 Nov 2016 12:50:31 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id EC2E0160AFE; Thu, 3 Nov 2016 11:50:31 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7007F160B1B for ; Thu, 3 Nov 2016 12:50:30 +0100 (CET) Received: (qmail 90021 invoked by uid 500); 3 Nov 2016 11:50:29 -0000 Mailing-List: contact commits-help@tinkerpop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tinkerpop.apache.org Delivered-To: mailing list commits@tinkerpop.apache.org Received: (qmail 89602 invoked by uid 99); 3 Nov 2016 11:50:29 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Nov 2016 11:50:29 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 25B58F170F; Thu, 3 Nov 2016 11:50:29 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: spmallette@apache.org To: commits@tinkerpop.apache.org Date: Thu, 03 Nov 2016 11:50:43 -0000 Message-Id: <580a6f547fcb4fa09f48f80620b2f14b@git.apache.org> In-Reply-To: <5b792d1f943d4027b8e0d56dd103a7a5@git.apache.org> References: <5b792d1f943d4027b8e0d56dd103a7a5@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [16/45] tinkerpop git commit: removed more method-based recursions in ImmutablePath and inlined the singleHead() and singleTail() methods as they are no longer interface methods and are only called in one other method. archived-at: Thu, 03 Nov 2016 11:50:32 -0000 removed more method-based recursions in ImmutablePath and inlined the singleHead() and singleTail() methods as they are no longer interface methods and are only called in one other method. Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/cd000995 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/cd000995 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/cd000995 Branch: refs/heads/TINKERPOP-1420 Commit: cd000995d1670170b9b5f3d726f20fb8cf45ffc9 Parents: 3caa5c8 Author: Marko A. Rodriguez Authored: Tue Nov 1 07:09:45 2016 -0600 Committer: Marko A. Rodriguez Committed: Tue Nov 1 07:09:45 2016 -0600 ---------------------------------------------------------------------- .../traversal/step/util/ImmutablePath.java | 67 ++++++++++---------- 1 file changed, 34 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cd000995/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 d64cdb4..4104da7 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 @@ -110,31 +110,11 @@ public class ImmutablePath implements Path, Serializable, Cloneable { @Override public A get(final int index) { - return (this.size() - 1) == index ? (A) this.currentObject : this.previousPath.get(index); - } - - - private final A getSingleHead(final String label) { + int counter = this.size(); ImmutablePath currentPath = this; - while (true) { - if (currentPath.isTail()) - return null; - else if (currentPath.currentLabels.contains(label)) + while(true) { + if(index == --counter) return (A) currentPath.currentObject; - else - currentPath = currentPath.previousPath; - } - } - - - private final A getSingleTail(final String label) { - A found = null; - ImmutablePath currentPath = this; - while (true) { - if (currentPath.isTail()) - return found; - else if (currentPath.currentLabels.contains(label)) - found = (A) currentPath.currentObject; currentPath = currentPath.previousPath; } } @@ -143,18 +123,39 @@ public class ImmutablePath implements Path, Serializable, Cloneable { public A get(final Pop pop, final String label) { if (Pop.all == pop) { // Recursively build the list to avoid building objects/labels collections. - final List list = null == this.previousPath ? new ArrayList<>() : this.previousPath.get(Pop.all, label); - // Add our object, if our step labels match. - if (this.currentLabels.contains(label)) - list.add((A) currentObject); + final List list = new ArrayList<>(); + ImmutablePath currentPath = this; + while (true) { + if (currentPath.isTail()) + break; + else if (currentPath.currentLabels.contains(label)) + list.add(0, currentPath.currentObject); + currentPath = currentPath.previousPath; + } return (A) list; - } else { - // Delegate to the non-throwing, optimized head/tail calculations. - final A single = Pop.first == pop ? this.getSingleTail(label) : this.getSingleHead(label); - // Throw if we didn't find the label. - if (null == single) + } else if (Pop.last == pop) { + ImmutablePath currentPath = this; + while (true) { + if (currentPath.isTail()) + throw Path.Exceptions.stepWithProvidedLabelDoesNotExist(label); + else if (currentPath.currentLabels.contains(label)) + return (A) currentPath.currentObject; + else + currentPath = currentPath.previousPath; + } + } else { // Pop.first + A found = null; + ImmutablePath currentPath = this; + while (true) { + if (currentPath.isTail()) + break; + else if (currentPath.currentLabels.contains(label)) + found = (A) currentPath.currentObject; + currentPath = currentPath.previousPath; + } + if (null == found) throw Path.Exceptions.stepWithProvidedLabelDoesNotExist(label); - return single; + return found; } }