groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cchamp...@apache.org
Subject [06/10] groovy git commit: Don't use exception for control flow
Date Wed, 23 May 2018 19:28:14 GMT
Don't use exception for control flow

It's extremely slow, as we generate tons of stacktraces for nothing!


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

Branch: refs/heads/master
Commit: a5c49a01678fe13145c8e32b415f68361544d06b
Parents: f810c80
Author: Cedric Champeau <cchampeau@apache.org>
Authored: Wed May 23 11:42:42 2018 +0200
Committer: Cedric Champeau <cchampeau@apache.org>
Committed: Wed May 23 11:47:19 2018 +0200

----------------------------------------------------------------------
 .../org/codehaus/groovy/antlr/GroovySourceAST.java | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/a5c49a01/src/main/java/org/codehaus/groovy/antlr/GroovySourceAST.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/antlr/GroovySourceAST.java b/src/main/java/org/codehaus/groovy/antlr/GroovySourceAST.java
index 80da241..1f0d8b5 100644
--- a/src/main/java/org/codehaus/groovy/antlr/GroovySourceAST.java
+++ b/src/main/java/org/codehaus/groovy/antlr/GroovySourceAST.java
@@ -62,7 +62,7 @@ public class GroovySourceAST extends CommonAST implements Comparable, SourceInfo
         if (t instanceof SourceInfo) {
             SourceInfo info = (SourceInfo) t;
             lineLast = info.getLineLast();
-            colLast  = info.getColumnLast(); 
+            colLast  = info.getColumnLast();
         }
     }
 
@@ -140,17 +140,16 @@ public class GroovySourceAST extends CommonAST implements Comparable,
SourceInfo
     }
 
     public GroovySourceAST childAt(int position) {
-        List list = new ArrayList();
+        int cur = 0;
         AST child = this.getFirstChild();
-        while (child != null) {
-            list.add(child);
+        while (child != null && cur <= position) {
+            if (cur == position) {
+                return (GroovySourceAST) child;
+            }
+            cur++;
             child = child.getNextSibling();
         }
-        try {
-            return (GroovySourceAST)list.get(position);
-        } catch (IndexOutOfBoundsException e) {
-            return null;
-        }
+        return null;
     }
 
     public GroovySourceAST childOfType(int type) {


Mime
View raw message