Skip to content

Commit 75cdf69

Browse files
committed
Adjust caching.
1 parent 3d7e5b3 commit 75cdf69

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

byte-buddy-dep/src/main/java/net/bytebuddy/description/method/ParameterList.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ abstract class ForLoadedExecutable<T> extends AbstractBase<ParameterDescription.
154154
protected final ParameterDescription.ForLoadedParameter.ParameterAnnotationSource parameterAnnotationSource;
155155

156156
/**
157-
* The number of parameters of this executable, or -1, if the size was not yet computed. This avoids recomputation
158-
* what can lead to an unreasonable performance impact if placed on a hot execution path. This field is not
159-
* volatile as the result is stable and can be recomputed from different threads.
157+
* The number of parameters of this executable, 0 if the size was not yet computed, or -1 if the list is empty.
158+
* This avoids recomputation what can lead to an unreasonable performance impact if placed on a hot execution
159+
* path. This field is not volatile as the result is stable and can be recomputed from different threads.
160160
*/
161161
private int size;
162162

@@ -169,7 +169,6 @@ abstract class ForLoadedExecutable<T> extends AbstractBase<ParameterDescription.
169169
protected ForLoadedExecutable(T executable, ParameterDescription.ForLoadedParameter.ParameterAnnotationSource parameterAnnotationSource) {
170170
this.executable = executable;
171171
this.parameterAnnotationSource = parameterAnnotationSource;
172-
size = -1;
173172
}
174173

175174
/**
@@ -236,10 +235,11 @@ public static ParameterList<ParameterDescription.InDefinedShape> of(Method metho
236235
* {@inheritDoc}
237236
*/
238237
public int size() {
239-
if (size == -1) {
240-
size = EXECUTABLE.getParameterCount(executable);
238+
if (size == 0) {
239+
int size = EXECUTABLE.getParameterCount(executable);
240+
this.size = size == 0 ? -1 : size;
241241
}
242-
return size;
242+
return size == -1 ? 0 : size;
243243
}
244244

245245
/**
@@ -584,9 +584,9 @@ class TypeSubstituting extends AbstractBase<ParameterDescription.InGenericShape>
584584
private final TypeDescription.Generic.Visitor<? extends TypeDescription.Generic> visitor;
585585

586586
/**
587-
* The number of parameters of this executable, or -1, if the size was not yet computed. This avoids recomputation
588-
* what can lead to an unreasonable performance impact if placed on a hot execution path. This field is not
589-
* volatile as the result is stable and can be recomputed from different threads.
587+
* The number of parameters of this executable, 0 if the size was not yet computed, or -1 if the list is empty.
588+
* This avoids recomputation what can lead to an unreasonable performance impact if placed on a hot execution
589+
* path. This field is not volatile as the result is stable and can be recomputed from different threads.
590590
*/
591591
private int size;
592592

@@ -603,7 +603,6 @@ public TypeSubstituting(MethodDescription.InGenericShape declaringMethod,
603603
this.declaringMethod = declaringMethod;
604604
this.parameterDescriptions = parameterDescriptions;
605605
this.visitor = visitor;
606-
size = -1;
607606
}
608607

609608
/**
@@ -617,10 +616,11 @@ public ParameterDescription.InGenericShape get(int index) {
617616
* {@inheritDoc}
618617
*/
619618
public int size() {
620-
if (size == -1) {
621-
size = parameterDescriptions.size();
619+
if (size == 0) {
620+
int size = parameterDescriptions.size();
621+
this.size = size == 0 ? -1 : size;
622622
}
623-
return size;
623+
return size == -1 ? 0 : size;
624624
}
625625
}
626626

0 commit comments

Comments
 (0)