3 ms·
The example of bad allocations def first[A](left: A, right: A): A = left first(12, 42) // => 12 actually allocates nothing, because both numbers are in
by jcdavis 9y ago
The example of bad allocations
def first[A](left: A, right: A): A = left
first(12, 42) // => 12
actually allocates nothing, because both numbers are in the Integer box cache range (-128 to 127 inclusive by default, but configurable to be greater). The general argument is good though, so mabye first(128,129) is a better example :)
- ychen306 9y agoSeems odd that the compiler can't inline this pattern.
- peoplewindow 9y agoIt probably can. Graal certainly could.
- fnl 9y agoActually, those are Scala code examples, so I believe it will be end up using ints for this case, not Integers. Edit: I'm wrong, the example still needs a @specialized version.