Aller au contenu

Inefficient Membership Test (ARCH9075)

Ce contenu n’est pas encore disponible dans votre langue.

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

Flags array.contains inside a loop - an O(n) scan per iteration; a Set makes it O(1).

for id in ids {
if blockedList.contains(id) { skip(id) }
}
let blocked = Set(blockedList)
for id in ids where blocked.contains(id) { skip(id) }

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