Skip to content

Commit fa02fc2

Browse files
committed
Address PR comments
1 parent 87e5e8d commit fa02fc2

2 files changed

Lines changed: 3 additions & 21 deletions

File tree

src/Microsoft.ComponentDetection.Common/PatternMatchingUtility.cs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static bool MatchesPattern(string pattern, string fileName)
2525
ArgumentNullException.ThrowIfNull(fileName);
2626
ArgumentNullException.ThrowIfNull(patterns);
2727

28-
return GetFirstMatchingPattern(fileName.AsSpan(), patterns);
28+
return Compile(patterns).GetMatchingPattern(fileName.AsSpan());
2929
}
3030

3131
public static CompiledMatcher Compile(IEnumerable<string> patterns)
@@ -40,24 +40,6 @@ public static CompiledMatcher Compile(string[] patterns)
4040
return new(patterns);
4141
}
4242

43-
private static string? GetFirstMatchingPattern(ReadOnlySpan<char> fileName, IEnumerable<string> patterns)
44-
{
45-
foreach (var pattern in patterns)
46-
{
47-
ArgumentNullException.ThrowIfNull(pattern);
48-
49-
if (IsPatternMatch(pattern, fileName))
50-
{
51-
return pattern;
52-
}
53-
}
54-
55-
return null;
56-
}
57-
58-
/// <summary>
59-
/// Fast path for pre-validated pattern arrays. Skips per-element null checks.
60-
/// </summary>
6143
private static string? GetFirstMatchingPattern(ReadOnlySpan<char> fileName, string[] patterns)
6244
{
6345
foreach (var pattern in patterns)
@@ -99,7 +81,7 @@ internal CompiledMatcher(string[] patterns)
9981
/// <returns>The first matching pattern, or <see langword="null"/> if no patterns match.</returns>
10082
public string? GetMatchingPattern(ReadOnlySpan<char> fileName) => GetFirstMatchingPattern(fileName, this.patterns);
10183

102-
private static void ValidatePatternElements(IEnumerable<string> patterns)
84+
private static void ValidatePatternElements(string[] patterns)
10385
{
10486
foreach (var pattern in patterns)
10587
{

src/Microsoft.ComponentDetection.Contracts/FileComponentDetector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public abstract class FileComponentDetector : IComponentDetector
3535
public abstract string Id { get; }
3636

3737
/// <summary>
38-
/// Gets the search patterns used to produce the list of valid folders to scan.
38+
/// Gets the search patterns used to produce the list of valid files to scan.
3939
/// The first pattern that matches a given file will be used to determine how that file is processed, so more specific patterns should be listed before more general ones. Wildcards are accepted.
4040
/// </summary>
4141
public abstract IList<string> SearchPatterns { get; }

0 commit comments

Comments
 (0)