Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate redundant lookups of classes and annotations #30891

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class InjectionPoint {
@Nullable
private volatile Annotation[] fieldAnnotations;

@Nullable
private volatile Annotation[] methodParameterAnnotations;

/**
* Create an injection point descriptor for a method or constructor parameter.
Expand Down Expand Up @@ -76,6 +78,7 @@ protected InjectionPoint(InjectionPoint original) {
new MethodParameter(original.methodParameter) : null);
this.field = original.field;
this.fieldAnnotations = original.fieldAnnotations;
this.methodParameterAnnotations = original.methodParameterAnnotations;
}

/**
Expand Down Expand Up @@ -129,7 +132,13 @@ public Annotation[] getAnnotations() {
return fieldAnnotations;
}
else {
return obtainMethodParameter().getParameterAnnotations();
Annotation[] methodParameterAnnotations = this.methodParameterAnnotations;
if (methodParameterAnnotations == null) {
methodParameterAnnotations =
obtainMethodParameter().getParameterAnnotations();
this.methodParameterAnnotations = methodParameterAnnotations;
}
return methodParameterAnnotations;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ public Object[] getArguments() {
* @see #invoke
*/
public void prepare() throws ClassNotFoundException, NoSuchMethodException {
if (this.staticMethod != null) {
Class<?> targetClass = getTargetClass();
if (targetClass == null && this.staticMethod != null) {
int lastDotIndex = this.staticMethod.lastIndexOf('.');
if (lastDotIndex == -1 || lastDotIndex == this.staticMethod.length()) {
throw new IllegalArgumentException(
Expand All @@ -164,11 +165,12 @@ public void prepare() throws ClassNotFoundException, NoSuchMethodException {
}
String className = this.staticMethod.substring(0, lastDotIndex);
String methodName = this.staticMethod.substring(lastDotIndex + 1);
this.targetClass = resolveClassName(className);
targetClass = resolveClassName(className);
this.targetClass = targetClass;
this.targetMethod = methodName;

}

Class<?> targetClass = getTargetClass();
String targetMethod = getTargetMethod();
Assert.notNull(targetClass, "Either 'targetClass' or 'targetObject' is required");
Assert.notNull(targetMethod, "Property 'targetMethod' is required");
Expand Down