diff --git a/src/main/java/org/codehaus/groovy/reflection/CachedClass.java b/src/main/java/org/codehaus/groovy/reflection/CachedClass.java index 574770ce5b3..cc9a27b3df3 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 Collection initValue() { @Override public Set initValue() { - Set res = new HashSet<>(0); - Class[] classes = getTheClass().getInterfaces(); + Set res = new HashSet<>(classes.length); for (Class cls : classes) { res.add(ReflectionCache.getCachedClass(cls)); } @@ -188,12 +187,13 @@ public Set initValue() { @Override public Set initValue() { - Set res = new HashSet<>(0); - - if (getTheClass().isInterface()) { + Class theClass = getTheClass(); + Class[] classes = theClass.getInterfaces(); + Set 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))