This PR polishes InjectionMetadata.forElements()
by removing an unnecessary branch and updating outdated Javadoc.
Comment From: jhoeller
Good catch, the javadoc is definitely out of date now. However, with respect to the implementation, the use of the empty list constant is intentional since it reduces the memory footprint for the common empty case... the next best thing we can do after using the InjectionMetadata.EMPTY
constant itself.
Comment From: izeye
@jhoeller Thanks for the feedback! I just thought that using the provided empty collection and using the empty list constant are the same in terms of memory footprint. Am I missing something?
Comment From: jhoeller
The provided collection is the fresh result from a new search, so a new instance every time. Since InjectionMetadata
is being cached, we'd make each such newly built empty collection instance long-lived. Replacing it with an empty constant makes the cached empty InjectionMetadata
instances all refer to a single long-lived collection constant.
It'd be even better to replace empty InjectionMetadata
instances themselves with a constant but that's unfortunately not possible due to the distinct class for the refresh check.
Comment From: izeye
@jhoeller Thanks for the explanation! Sorry, I just saw the code snippet only and didn't know the caching part. I reverted it.