Repository: groovy Updated Branches: refs/heads/master 05b5bf770 -> 3e2f6d6f8
Minor refactoring: invoking `toArray` Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/3e2f6d6f Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/3e2f6d6f Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/3e2f6d6f Branch: refs/heads/master Commit: 3e2f6d6f8eb120dd9e61dbf15a8763df3993ebfa Parents: 05b5bf7 Author: sunlan <[email protected]> Authored: Fri Nov 24 08:23:59 2017 +0800 Committer: sunlan <[email protected]> Committed: Fri Nov 24 08:25:17 2017 +0800 ---------------------------------------------------------------------- src/main/groovy/util/ProxyGenerator.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/3e2f6d6f/src/main/groovy/util/ProxyGenerator.java ---------------------------------------------------------------------- diff --git a/src/main/groovy/util/ProxyGenerator.java b/src/main/groovy/util/ProxyGenerator.java index 62e9c6c..da12b97 100644 --- a/src/main/groovy/util/ProxyGenerator.java +++ b/src/main/groovy/util/ProxyGenerator.java @@ -50,7 +50,8 @@ import java.util.Set; * @author Cedric Champeau */ public class ProxyGenerator { - private static final Class[] EMPTY_INTERFACE_ARRAY = new Class[0]; + private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; + private static final Class[] EMPTY_INTERFACE_ARRAY = EMPTY_CLASS_ARRAY; private static final Map<Object,Object> EMPTY_CLOSURE_MAP = Collections.emptyMap(); private static final Set<String> EMPTY_KEYSET = Collections.emptySet(); @@ -208,7 +209,9 @@ public class ProxyGenerator { } private ProxyGeneratorAdapter createAdapter(Map closureMap, List<Class> interfaces, Class delegateClass, Class baseClass) { - Class[] intfs = interfaces != null ? interfaces.toArray(new Class[interfaces.size()]) : EMPTY_INTERFACE_ARRAY; + // According to https://shipilev.net/blog/2016/arrays-wisdom-ancients/#_conclusion + // toArray(new T[0]) seems faster, safer, and contractually cleaner, and therefore should be the default choice now. + Class[] intfs = interfaces != null ? interfaces.toArray(EMPTY_CLASS_ARRAY) : EMPTY_INTERFACE_ARRAY; Class base = baseClass; if (base == null) { if (intfs.length > 0) {
