Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X e3df0782a -> 97cbe8ee7


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/97cbe8ee
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/97cbe8ee
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/97cbe8ee

Branch: refs/heads/GROOVY_2_5_X
Commit: 97cbe8ee7b30f8e291c46f517bf182317528d3a7
Parents: e3df078
Author: sunlan <[email protected]>
Authored: Fri Dec 15 09:00:31 2017 +0800
Committer: sunlan <[email protected]>
Committed: Fri Dec 15 09:00:31 2017 +0800

----------------------------------------------------------------------
 .../groovy/control/CompilationUnit.java         | 21 ++++++++++----------
 1 file changed, 10 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/97cbe8ee/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 64a1b43..dab0e55 100644
--- a/src/main/org/codehaus/groovy/control/CompilationUnit.java
+++ b/src/main/org/codehaus/groovy/control/CompilationUnit.java
@@ -1018,7 +1018,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()) {
@@ -1028,8 +1028,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++) {
@@ -1050,10 +1051,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;
@@ -1072,16 +1074,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++;
                     }

Reply via email to