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:
@@ -148,12 +148,8 @@ public class AsmUtil {
|
||||
return type == Type.INT_TYPE || type == Type.SHORT_TYPE || type == Type.BYTE_TYPE || type == Type.CHAR_TYPE;
|
||||
}
|
||||
|
||||
public static boolean isNonFloatingPointPrimitive(Type type) {
|
||||
return isIntPrimitive(type) || type == Type.LONG_TYPE || type == Type.BOOLEAN_TYPE;
|
||||
}
|
||||
|
||||
public static boolean isIntPrimitiveOrBoolean(Type type) {
|
||||
return isIntPrimitive(type) || type == Type.BOOLEAN_TYPE;
|
||||
public static boolean isIntOrLongPrimitive(Type type) {
|
||||
return isIntPrimitive(type) || type == Type.LONG_TYPE;
|
||||
}
|
||||
|
||||
public static boolean isNumberPrimitiveOrBoolean(Type type) {
|
||||
|
||||
@@ -249,7 +249,7 @@ class BoxedToPrimitiveEquality private constructor(
|
||||
@JvmStatic
|
||||
fun isApplicable(opToken: IElementType, leftType: Type, rightType: Type) =
|
||||
(opToken == KtTokens.EQEQ || opToken == KtTokens.EXCLEQ) &&
|
||||
AsmUtil.isNonFloatingPointPrimitive(rightType) &&
|
||||
AsmUtil.isIntOrLongPrimitive(rightType) &&
|
||||
AsmUtil.isBoxedTypeOf(leftType, rightType)
|
||||
}
|
||||
}
|
||||
@@ -323,7 +323,7 @@ class PrimitiveToBoxedEquality private constructor(
|
||||
@JvmStatic
|
||||
fun isApplicable(opToken: IElementType, leftType: Type, rightType: Type) =
|
||||
(opToken == KtTokens.EQEQ || opToken == KtTokens.EXCLEQ) &&
|
||||
AsmUtil.isNonFloatingPointPrimitive(leftType) &&
|
||||
AsmUtil.isIntOrLongPrimitive(leftType) &&
|
||||
AsmUtil.isBoxedTypeOf(rightType, leftType)
|
||||
}
|
||||
}
|
||||
@@ -402,7 +402,7 @@ class PrimitiveToObjectEquality private constructor(
|
||||
@JvmStatic
|
||||
fun isApplicable(opToken: IElementType, leftType: Type, rightType: Type) =
|
||||
(opToken == KtTokens.EQEQ || opToken == KtTokens.EXCLEQ) &&
|
||||
AsmUtil.isNonFloatingPointPrimitive(leftType) &&
|
||||
AsmUtil.isIntOrLongPrimitive(leftType) &&
|
||||
rightType.sort == Type.OBJECT
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user