Repository: groovy Updated Branches: refs/heads/GROOVY_2_4_X 4cb24e9f8 -> cb39f7f72
Trivial refactoring (cherry picked from commit ed1c4c4b9327d10672a6d5f9acdb337a1601ed4c) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/cb39f7f7 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/cb39f7f7 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/cb39f7f7 Branch: refs/heads/GROOVY_2_4_X Commit: cb39f7f72a0271cdf7fa3f6507b8597ffbe4a7d5 Parents: 4cb24e9 Author: sunlan <[email protected]> Authored: Fri Dec 15 09:01:24 2017 +0800 Committer: sunlan <[email protected]> Committed: Fri Dec 15 09:01:24 2017 +0800 ---------------------------------------------------------------------- .../groovy/control/CompilationUnit.java | 21 ++++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/cb39f7f7/src/main/org/codehaus/groovy/control/CompilationUnit.java ---------------------------------------------------------------------- diff --git a/src/main/org/codehaus/groovy/control/CompilationUnit.java b/src/main/org/codehaus/groovy/control/CompilationUnit.java index 59fd993..c4750ba 100644 --- a/src/main/org/codehaus/groovy/control/CompilationUnit.java +++ b/src/main/org/codehaus/groovy/control/CompilationUnit.java @@ -1013,7 +1013,7 @@ public class CompilationUnit extends ProcessingUnit { return count; } - private List getPrimaryClassNodes(boolean sort) { + private List<ClassNode> getPrimaryClassNodes(boolean sort) { List<ClassNode> unsorted = new ArrayList<ClassNode>(); for (ModuleNode module : this.ast.getModules()) { for (ClassNode classNode : module.getClasses()) { @@ -1023,8 +1023,9 @@ public class CompilationUnit extends ProcessingUnit { if (!sort) return unsorted; - int[] indexClass = new int[unsorted.size()]; - int[] indexInterface = new int[unsorted.size()]; + int unsortedSize = unsorted.size(); + int[] indexClass = new int[unsortedSize]; + int[] indexInterface = new int[unsortedSize]; { int i = 0; for (Iterator<ClassNode> iter = unsorted.iterator(); iter.hasNext(); i++) { @@ -1045,10 +1046,11 @@ public class CompilationUnit extends ProcessingUnit { } private static List<ClassNode> getSorted(int[] index, List<ClassNode> unsorted) { - List<ClassNode> sorted = new ArrayList<ClassNode>(unsorted.size()); - for (int i = 0; i < unsorted.size(); i++) { + int unsortedSize = unsorted.size(); + List<ClassNode> sorted = new ArrayList<ClassNode>(unsortedSize); + for (int i = 0; i < unsortedSize; i++) { int min = -1; - for (int j = 0; j < unsorted.size(); j++) { + for (int j = 0; j < unsortedSize; j++) { if (index[j] == -1) continue; if (min == -1 || index[j] < index[min]) { min = j; @@ -1067,16 +1069,13 @@ public class CompilationUnit extends ProcessingUnit { * through the current phase. */ public void applyToPrimaryClassNodes(PrimaryClassNodeOperation body) throws CompilationFailedException { - Iterator classNodes = getPrimaryClassNodes(body.needSortedInput()).iterator(); - while (classNodes.hasNext()) { + for (ClassNode classNode : getPrimaryClassNodes(body.needSortedInput())) { SourceUnit context = null; try { - ClassNode classNode = (ClassNode) classNodes.next(); context = classNode.getModule().getContext(); if (context == null || context.phase < phase || (context.phase == phase && !context.phaseComplete)) { int offset = 1; - Iterator<InnerClassNode> iterator = classNode.getInnerClasses(); - while (iterator.hasNext()) { + for (Iterator<InnerClassNode> iterator = classNode.getInnerClasses(); iterator.hasNext(); ) { iterator.next(); offset++; }
