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

Use Method::getParameterCount where possible #23949

merged 1 commit into from Nov 7, 2019


Copy link

stsypanov commented Nov 7, 2019

We often use Method.getParameterTypes() which clones underlying array:

public Class<?>[] getParameterTypes() {
    return parameterTypes.clone();

The problem is that array is often used only to get its length, so we allocate memory mostly in vain.

Instead in numerous cases we call Method.getParameterCount introduced in Java 8:

public int getParameterCount() { return parameterTypes.length; }

which doesn't allocate.

In cases where we still need parameter types we can postpone retrieving it until it becomes inevitable.

@jhoeller jhoeller self-assigned this Nov 7, 2019
@jhoeller jhoeller added this to the 5.2.2 milestone Nov 7, 2019
@jhoeller jhoeller merged commit f5ae3c7 into spring-projects:master Nov 7, 2019
1 check passed
1 check passed
ci/pivotal-cla Thank you for signing the Contributor License Agreement!
@stsypanov stsypanov deleted the stsypanov:param-count branch Nov 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.