GitHub user KoenDG opened a pull request:
https://github.com/apache/kafka/pull/4226
MINOR: Arrays.toList replaced with Collections.singletonList() where
possible.
This is something I did after my working hours, I would ask people
reviewing this do the same, don't take time for this during your work hours.
It's not actual functionality, it is an internal rewrite based on suggestions
provided by the static code analysis built into the Intellij IDE.
I try to keep such a PR as limited as possible, for clarity of reading.
==========
In places where Arrays.asList() is given exactly 1 argument, replace it
with Collections.singletonList().
Internally, this is a smaller object, so it uses a bit less memory at
runtime.
An important thing to note is that you cannot add anything to such a list.
So if it is returned through a method into a random `List<>` object, performing
`add()` on it will throw an exception.
I checked every usage of all replaced instances, they're only ever returned
to be read, so this should not occur. A
One might say this is a micro-optimization, I would say that's true, it is.
It's up to the maintainers whether or not they want this in. Personally I
checked all code usages and did not find a point where an exception would be
caused because of these changes. So it should not break anything and provide a
tiny improvement in terms of memory footprint at runtime.
*Summary of testing strategy (including rationale)
for the feature or bug fix. Unit and/or integration
tests are expected for any behaviour change and
system tests should be considered for larger changes.*
### Committer Checklist (excluded from commit message)
- [ ] Verify design and implementation
- [ ] Verify test coverage and CI build status
- [ ] Verify documentation (including upgrade notes)
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/KoenDG/kafka singletonlist
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/kafka/pull/4226.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #4226
----
commit 772d65f2411aac1f78b12cd4a52547a48fa8f9f4
Author: KoenDG <[email protected]>
Date: 2017-11-16T19:42:54Z
In places where Arrays.asList() is given exactly 1 argument, replace it
with Collections.singletonList().
Internally, this is a smaller object, so it uses a bit less memory at
runtime.
An important thing to note is that you cannot add anything to such a list.
So if it is returned through a method into a random List<> object, performing
add() on it will throw an exception.
I checked every usage of all replaced instances, they're only ever returned
to be read, so this should not occur.
One might say this is a micro-optimization, I would say that's true, it is.
It's up to the maintainers whether or not they want this in. Personally I
checked all code usages and did not find a point where an exception would be
caused because of these changes. So it should not break anything and provide a
tiny improvement in terms of memory footprint at runtime.
Import changes due to Intellij squashing imports into a * import. Had to
update my settings so it won't happen again.
----
---