tweak containment check even more

This commit is contained in:
Irmen de Jong 2024-09-13 00:02:26 +02:00
parent ac0c8a68f6
commit cf551d2cc7
2 changed files with 7 additions and 2 deletions

View File

@ -149,8 +149,10 @@ internal class VariousCleanups(val program: Program, val errors: IErrorReporter,
return listOf(IAstModification.ReplaceNode(expr, compare, parent))
}
}
if(values.size<3)
return noModifications // replacement only worthwhile for 3 or more values
if(values.size<2)
return noModifications
// replace x==1 or x==2 or x==3 with a containment check x in [1,2,3]
val valueCopies = values.sortedBy { it.number }.map { it.copy() }
val arrayType = ElementToArrayTypes.getValue(elementType)
val valuesArray = ArrayLiteral(InferredTypes.InferredType.known(arrayType), valueCopies.toTypedArray(), expr.position)

View File

@ -22,5 +22,8 @@ main {
if w==1313 or w==4242 or w==9999 or w==10101 ; optimize the containment check to not always use an array + jsr
txt.print("yep4\n")
if w==1313 or w==9999 ; optimize the containment check to not always use an array + jsr
txt.print("yep5\n")
}
}