groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [1/3] groovy git commit: Trivial refactoring: avoid calling `toArray` with pre-sized array parameter
Date Mon, 02 Apr 2018 23:58:54 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 0e737d7b9 -> d524b2ff9


Trivial refactoring: avoid calling `toArray` with pre-sized array parameter


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

Branch: refs/heads/master
Commit: d524b2ff964b07fbb443d38fc3df678dd6b5cb80
Parents: c0b5ea2
Author: sunlan <sunlan@apache.org>
Authored: Tue Apr 3 07:57:23 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Tue Apr 3 07:58:46 2018 +0800

----------------------------------------------------------------------
 src/main/groovy/groovy/lang/MetaMethod.java                  | 1 +
 .../java/org/codehaus/groovy/reflection/CachedClass.java     | 8 ++++----
 2 files changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/d524b2ff/src/main/groovy/groovy/lang/MetaMethod.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/MetaMethod.java b/src/main/groovy/groovy/lang/MetaMethod.java
index c58d6b7..10815ed 100644
--- a/src/main/groovy/groovy/lang/MetaMethod.java
+++ b/src/main/groovy/groovy/lang/MetaMethod.java
@@ -34,6 +34,7 @@ import java.lang.reflect.Modifier;
  * @author Alex Tkachman
  */
 public abstract class MetaMethod extends ParameterTypes implements Cloneable {
+    public static final MetaMethod[] EMPTY_ARRAY = new MetaMethod[0];
     private String signature;
     private String mopName;
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/d524b2ff/src/main/java/org/codehaus/groovy/reflection/CachedClass.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/reflection/CachedClass.java b/src/main/java/org/codehaus/groovy/reflection/CachedClass.java
index 80bc040..9204be2 100644
--- a/src/main/java/org/codehaus/groovy/reflection/CachedClass.java
+++ b/src/main/java/org/codehaus/groovy/reflection/CachedClass.java
@@ -217,7 +217,7 @@ public class CachedClass {
         }
     };
 
-    static final MetaMethod[] EMPTY = new MetaMethod[0];
+    static final MetaMethod[] EMPTY = MetaMethod.EMPTY_ARRAY;
 
     int hashCode;
 
@@ -401,7 +401,7 @@ public class CachedClass {
             addSubclassExpandos(arr, mc);
         }
 
-        return arr.toArray(new MetaMethod[arr.size()]);
+        return arr.toArray(MetaMethod.EMPTY_ARRAY);
     }
 
     private void addSubclassExpandos(List<MetaMethod> arr, MetaClass mc) {
@@ -453,7 +453,7 @@ public class CachedClass {
 
     private void updateSetNewMopMethods(List<MetaMethod> arr) {
         if (arr != null) {
-            final MetaMethod[] metaMethods = arr.toArray(new MetaMethod[arr.size()]);
+            final MetaMethod[] metaMethods = arr.toArray(MetaMethod.EMPTY_ARRAY);
             classInfo.dgmMetaMethods = metaMethods;
             classInfo.newMetaMethods = metaMethods;
         }
@@ -501,7 +501,7 @@ public class CachedClass {
         List<MetaMethod> res = new ArrayList<MetaMethod>();
         res.addAll(Arrays.asList(classInfo.newMetaMethods));
         res.addAll(arr);
-        classInfo.newMetaMethods = res.toArray(new MetaMethod[res.size()]);
+        classInfo.newMetaMethods = res.toArray(MetaMethod.EMPTY_ARRAY);
         Class theClass = classInfo.getCachedClass().getTheClass();
         if (theClass==Closure.class || theClass==Class.class) {
             ClosureMetaClass.resetCachedMetaClasses();


Mime
View raw message