Ir al contenido

Inefficient Membership Test (ARCH8075)

Esta página aún no está disponible en tu idioma.

Key kotlin.performance.inefficient-membership-test · Severity warning · Category performance

Flags in list / list.contains inside a loop - an O(n) scan per iteration; a Set makes it O(1). Ranges (list.indices, 0 until n) and collections of fewer than five literal entries are excepted.

for (id in ids) {
if (id in blockedList) skip(id)
}
val blocked = blockedList.toSet()
for (id in ids) {
if (id in blocked) skip(id)
}

Convert the collection to a Set once, outside the loop.