Don't analyze method in RNCE if there're no optimizable instructions

This commit is contained in:
Dmitry Petrov
2017-10-04 11:59:48 +03:00
parent 0bda2732e5
commit d31efaa7ac
@@ -46,6 +46,8 @@ class RedundantNullCheckMethodTransformer : MethodTransformer() {
private var changes = false
fun run(): Boolean {
if (methodNode.instructions.toArray().none { it.isOptimizable() }) return false
val checkedReferenceTypes = analyzeTypesAndRemoveDeadCode()
eliminateRedundantChecks(checkedReferenceTypes)
@@ -120,6 +122,12 @@ class RedundantNullCheckMethodTransformer : MethodTransformer() {
return nullabilityMap
}
private fun AbstractInsnNode.isOptimizable() =
opcode == Opcodes.IFNULL ||
opcode == Opcodes.IFNONNULL ||
opcode == Opcodes.INSTANCEOF ||
isCheckExpressionValueIsNotNull()
private fun transformTrivialChecks(nullabilityMap: Map<AbstractInsnNode, StrictBasicValue>) {
for ((insn, value) in nullabilityMap) {
val nullability = value.getNullability()