Skip to content

Commit

Permalink
chore(common-utils): Only decide once which match() to call
Browse files Browse the repository at this point in the history
This is a fixup for 32ab460 which forgot about the intended optimization
done by the previous implementation.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Dec 12, 2024
1 parent 23c9bb0 commit 709053a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions utils/common/src/main/kotlin/FileMatcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ class FileMatcher(
* Return true if [path] is matched by any of [patterns], false otherwise. The [path] must use '/' as
* separators, if it contains any.
*/
fun match(patterns: Collection<String>, path: String, ignoreCase: Boolean = false) =
patterns.any { pattern -> match(pattern, path, ignoreCase) }
fun match(patterns: Collection<String>, path: String, ignoreCase: Boolean = false): Boolean {
// Only decide once for all patterns which function to call.
val match = if (ignoreCase) matchCaseInsensitive else matchCaseSensitive

return patterns.any { pattern -> match(pattern, path) }
}
}

constructor(vararg patterns: String, ignoreCase: Boolean = false) : this(patterns.asList(), ignoreCase)
Expand Down

0 comments on commit 709053a

Please sign in to comment.