This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new c66f1042af Trivial tweak: set initial capacity
c66f1042af is described below

commit c66f1042af297acea956c76203939932f47362aa
Author: Daniel Sun <[email protected]>
AuthorDate: Sun Jan 12 05:15:53 2025 +0900

    Trivial tweak: set initial capacity
---
 .../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 574770ce5b..cc9a27b3df 100644
--- a/src/main/java/org/codehaus/groovy/reflection/CachedClass.java
+++ b/src/main/java/org/codehaus/groovy/reflection/CachedClass.java
@@ -173,9 +173,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));
             }
@@ -188,12 +187,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))

Reply via email to