From 07ec15679a6aa4448787c9ed98fa47b87b499c98 Mon Sep 17 00:00:00 2001 From: Marcelo Fabri Date: Sat, 4 Aug 2018 23:41:52 -0700 Subject: [PATCH] Improve empty_parentheses_with_trailing_closure performance on Swift 4.2 --- .../Rules/EmptyParenthesesWithTrailingClosureRule.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/SwiftLintFramework/Rules/EmptyParenthesesWithTrailingClosureRule.swift b/Source/SwiftLintFramework/Rules/EmptyParenthesesWithTrailingClosureRule.swift index fa5df3808..60565cab8 100644 --- a/Source/SwiftLintFramework/Rules/EmptyParenthesesWithTrailingClosureRule.swift +++ b/Source/SwiftLintFramework/Rules/EmptyParenthesesWithTrailingClosureRule.swift @@ -70,6 +70,12 @@ public struct EmptyParenthesesWithTrailingClosureRule: ASTRule, CorrectableRule, return [] } + // avoid the more expensive regex match if there's no trailing closure in the substructure + if SwiftVersion.current >= .fourDotTwo, + dictionary.substructure.last?.kind.flatMap(SwiftExpressionKind.init(rawValue:)) != .closure { + return [] + } + let rangeStart = nameOffset + nameLength let rangeLength = (offset + length) - (nameOffset + nameLength) let regex = EmptyParenthesesWithTrailingClosureRule.emptyParenthesesRegex