Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR optimizes (mostly)
Function0
allocations that originate frommap.getOrElse(key, ???)
. In Scala 2, the optimization is fairly straight-forward; we just need to store the default value in aFunction0
. Since=> A
compiles to() => A
, this means that invocations of thegetOrElse(key, DefaultValueFn())
don't create aFunction0
.In Scala 3 however, it's slightly more complex. For some reason (might be a bug, I'll open an issue in Dotty about it), this works only if the val is annotated with
@static
, which compiles to afinal static
field. To avoid having to do this everywhere, I added a package-privatesyntax
object with thegetOrElseNull
method.I've also noticed some small optimizations that could be done here and there so I did them as part of this PR