You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2018/04/03 00:02:09 UTC
[3/3] groovy git commit: Trivial refactoring: avoid calling `toArray`
with pre-sized array parameter
Trivial refactoring: avoid calling `toArray` with pre-sized array parameter
(cherry picked from commit d524b2f)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/7a614eed
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/7a614eed
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/7a614eed
Branch: refs/heads/GROOVY_2_5_X
Commit: 7a614eed58610ebd85658a7d65cbeb3b316b8148
Parents: d319b1c
Author: sunlan <su...@apache.org>
Authored: Tue Apr 3 07:57:23 2018 +0800
Committer: sunlan <su...@apache.org>
Committed: Tue Apr 3 08:01: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/7a614eed/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/7a614eed/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();