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 ae3cca0f1e Trivial tweak: Cache `thisType`
ae3cca0f1e is described below
commit ae3cca0f1e0bf1e53c433508274f90f444192798
Author: Daniel Sun <[email protected]>
AuthorDate: Fri Dec 27 22:25:07 2024 +0900
Trivial tweak: Cache `thisType`
---
src/main/java/groovy/lang/Closure.java | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/main/java/groovy/lang/Closure.java
b/src/main/java/groovy/lang/Closure.java
index 8524901aff..4ba76aa440 100644
--- a/src/main/java/groovy/lang/Closure.java
+++ b/src/main/java/groovy/lang/Closure.java
@@ -290,10 +290,15 @@ public abstract class Closure<V> extends
GroovyObjectSupport implements Cloneabl
return thisObject;
}
- private Class getThisType() {
- Class thisType = getClass();
- while (GeneratedClosure.class.isAssignableFrom(thisType)) {
- thisType = thisType.getEnclosingClass();
+ private Class<?> thisType;
+ private Class<?> getThisType() {
+ Class<?> thisType = this.thisType;
+ if (thisType == null) {
+ thisType = getClass();
+ while (GeneratedClosure.class.isAssignableFrom(thisType)) {
+ thisType = thisType.getEnclosingClass();
+ }
+ this.thisType = thisType;
}
return thisType;
}