Prefer compact bytecode for primitive/object comparisons with Boolean

'java.lang.Boolean#valueOf' doesn't allocate new objects
(it uses pre-allocated singletons for 'true' and 'false').
This commit is contained in:
Dmitry Petrov
2017-07-17 11:42:54 +03:00
parent 8e9c0294fe
commit e1a55e8dec
5 changed files with 14 additions and 18 deletions

View File

@@ -16,11 +16,11 @@ fun testInt2(a: Int?, b: Int) = a != b
fun testLong1(a: Long?, b: Long) = a == b
fun testLong2(a: Long?, b: Long) = a != b
// 2 booleanValue
// 2 charValue
// 2 byteValue
// 2 shortValue
// 2 intValue
// 2 longValue
// 0 valueOf
// 0 areEqual
// 2 valueOf
// 2 Boolean.valueOf
// 2 areEqual

View File

@@ -16,11 +16,11 @@ fun testInt2(a: Int, b: Int?) = a != b
fun testLong1(a: Long, b: Long?) = a == b
fun testLong2(a: Long, b: Long?) = a != b
// 2 booleanValue
// 2 charValue
// 2 byteValue
// 2 shortValue
// 2 intValue
// 2 longValue
// 0 valueOf
// 0 areEqual
// 2 valueOf
// 2 Boolean.valueOf
// 2 areEqual

View File

@@ -16,11 +16,11 @@ fun testInt2(a: Int, b: Any?) = a != b
fun testLong1(a: Long, b: Any?) = a == b
fun testLong2(a: Long, b: Any?) = a != b
// 2 booleanValue
// 2 charValue
// 2 byteValue
// 2 shortValue
// 2 intValue
// 2 longValue
// 0 valueOf
// 0 areEqual
// 2 valueOf
// 2 Boolean.valueOf
// 2 areEqual