Ir al contenido

Regex Recompiled In Loop (ARCH9073)

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

Key swift.performance.regex-recompiled-in-loop · Severity warning · Category performance

Flags NSRegularExpression(pattern:) / Regex(...) constructed inside a loop body.

for line in lines {
let re = try NSRegularExpression(pattern: "\\d+")
}
let re = try NSRegularExpression(pattern: "\\d+")
for line in lines { _ = re.firstMatch(in: line, range: .init(location: 0, length: line.utf16.count)) }

Hoist the regular expression out of the loop.