(groovy) branch GROOVY_4_0_X updated: Trivial tweak: set initial capacity

2025-01-11 Thread sunlan
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 0fc66ef5cb Trivial tweak: set initial capacity
0fc66ef5cb is described below

commit 0fc66ef5cbd8318fbf4702ded316800455ce864e
Author: Daniel Sun 
AuthorDate: Sun Jan 12 13:38:38 2025 +0900

Trivial tweak: set initial capacity
---
 .../java/org/codehaus/groovy/runtime/metaclass/ClosureMetaClass.java | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git 
a/src/main/java/org/codehaus/groovy/runtime/metaclass/ClosureMetaClass.java 
b/src/main/java/org/codehaus/groovy/runtime/metaclass/ClosureMetaClass.java
index fc17726f63..8fda238aab 100644
--- a/src/main/java/org/codehaus/groovy/runtime/metaclass/ClosureMetaClass.java
+++ b/src/main/java/org/codehaus/groovy/runtime/metaclass/ClosureMetaClass.java
@@ -145,9 +145,10 @@ public final class ClosureMetaClass extends MetaClassImpl {
 } else if (arguments.length == 1 && arguments[0] == null) {
 return 
MetaClassHelper.chooseMostGeneralMethodWith1NullParam(methods);
 } else {
-List matchingMethods = new ArrayList();
 final Object[] data = methods.getArray();
-for (int i = 0, n = methods.size(); i < n; i += 1) {
+final int methodCount = methods.size();
+List matchingMethods = new ArrayList(methodCount);
+for (int i = 0; i < methodCount; i += 1) {
 Object method = data[i];
 
 // making this false helps find matches



(groovy) branch GROOVY_4_0_X updated: Trivial tweak: set initial capacity

2025-01-11 Thread sunlan
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 
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 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));
 }
@@ -211,12 +210,13 @@ public class CachedClass {
 
 @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))