Regex Recompiled In Loop (ARCH9073)
هذا المحتوى غير متوفر بلغتك بعد.
Key swift.performance.regex-recompiled-in-loop · Severity warning · Category performance
Flags NSRegularExpression(pattern:) / Regex(...) constructed inside a loop body.
Incorrect
Section titled “Incorrect”for line in lines { let re = try NSRegularExpression(pattern: "\\d+")}Correct
Section titled “Correct”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.