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

Consistent use of Collection.toArray with zero-sized array argument [SPR-16523] #21066

Closed
spring-projects-issues opened this issue Feb 22, 2018 · 1 comment
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 22, 2018

Juergen Hoeller opened SPR-16523 and commented

Aligned with spring-projects/spring-boot#12160, let's revisit all the Collection.toArray call in the codebase and consistently use the toArray(new T[0]) pattern over pre-initialized arrays with a given length. In contrast to the established latter pattern, the former turns out to be more performant on modern JVMs since it doesn't initialize the array with null values first and allows for using efficient array cloning mechanisms underneath.


Affects: 5.0.4

Issue Links:

Referenced from: commits a5cbf5f

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

We're also consistently using StringUtils.toStringArray and ClassUtils.toClassArray across the codebase now, as shortcuts with improved readability. ClassUtils.toClassArray was missed in the nullability revision and got aligned as a non-null variant a la StringUtils.toStringArray now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants