-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Remove inefficiency in HttpStatus.series() #22366
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
Conversation
@roookeee Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@roookeee Thank you for signing the Contributor License Agreement! |
Computing and storing the |
We trade dynamic allocation and dynamic computation vs. static allocation and a one-time evaluation at class-loading-time. I for one think the static memory overhead by storing the value in the Caching the results in a field of Another approach would be to include the I use a fluent error-handling class with makes heavy use of |
Any update on this? |
@roookeee Could you please update the PR with your proposal?
|
Alright, will do so in the near future |
I have adjusted the PR to reflect your implementation wishes. In my opinion the other variant was more elegant, but I see that it's a subjective topic. I added a comment in the newly added test to justify it's surprising existence. |
Currently the
Series
value for aHttpStatus
is always evaluated which in turn costs an allocation of aSeries
array by usingSeries.values()
which does a defensive copy.I moved the
Series
value intoHttpStatus
and calculate it in the constructor as manually passing it for every constant seems unnecessary.Furthermore I deleted a JavaDoc about an
IllegalArgumentException
which cannot occur for any validHttpStatus
. If need be I would volunteer to add a unit test so this doesn't fail in the future.The method
Series.valueOf(HttpStatus)
could be removed / deprecated by this change but I don't think that's for me to decide :)