You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by cc...@apache.org on 2018/05/23 19:28:32 UTC
[6/9] groovy git commit: Don't use exception for control flow
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/89e2423c
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/89e2423c
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/89e2423c
Branch: refs/heads/GROOVY_2_5_X
Commit: 89e2423c7037d3a7c706eead3cc05747b3ac4dce
Parents: a815db1
Author: Cedric Champeau <cc...@apache.org>
Authored: Wed May 23 11:42:42 2018 +0200
Committer: Cedric Champeau <cc...@apache.org>
Committed: Wed May 23 21:23:46 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/89e2423c/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) {