This is an automated email from the ASF dual-hosted git repository. sunlan pushed a commit to branch GROOVY_4_0_X in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push: new a92ba2f47a Trivial tweak: set initial capacity a92ba2f47a is described below commit a92ba2f47a2b5d27b6f4b89edcbfcdb00f15a62c Author: Daniel Sun <sun...@apache.org> AuthorDate: Sun Jan 12 05:15:53 2025 +0900 Trivial tweak: set initial capacity (cherry picked from commit c66f1042af297acea956c76203939932f47362aa) --- .../java/org/codehaus/groovy/reflection/CachedClass.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/codehaus/groovy/reflection/CachedClass.java b/src/main/java/org/codehaus/groovy/reflection/CachedClass.java index fbfc3cad07..1515091e3e 100644 --- a/src/main/java/org/codehaus/groovy/reflection/CachedClass.java +++ b/src/main/java/org/codehaus/groovy/reflection/CachedClass.java @@ -196,9 +196,8 @@ public class CachedClass { @Override public Set<CachedClass> initValue() { - Set<CachedClass> res = new HashSet<>(0); - Class[] classes = getTheClass().getInterfaces(); + Set<CachedClass> res = new HashSet<>(classes.length); for (Class cls : classes) { res.add(ReflectionCache.getCachedClass(cls)); } @@ -211,12 +210,13 @@ public class CachedClass { @Override public Set<CachedClass> initValue() { - Set<CachedClass> res = new HashSet<>(0); - - if (getTheClass().isInterface()) { + Class<?> theClass = getTheClass(); + Class[] classes = theClass.getInterfaces(); + Set<CachedClass> res = new HashSet<>(classes.length + 8); + if (theClass.isInterface()) { res.add(CachedClass.this); } - Class[] classes = getTheClass().getInterfaces(); + for (Class cls : classes) { CachedClass aClass = ReflectionCache.getCachedClass(cls); if (!res.contains(aClass))