Skip to content

Commit 728229e

Browse files
committed
Fix code review findings
1 parent c870b0d commit 728229e

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/FilePathFilter.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,33 +64,33 @@ public IEnumerable<FileInfo> Filter(IEnumerable<FileInfo> files)
6464
pathFilters.Add(new PathFilter(new Regex(regex, RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline), include));
6565
}
6666

67-
var fileIndex = files.ToDictionary(f => f, f => new FileInclusion(FileUtils.ConvertToUnix(f.FullName.ToLowerInvariant()).Replace(rootFolder, string.Empty).TrimStart('/'), pathFilters.All(f => !f.Include)));
67+
var unfilteredResult = files.Select(f =>
68+
new
69+
{
70+
FileInfo = f,
71+
FileInclusion = new FileInclusion(
72+
FileUtils.ConvertToUnix(f.FullName.ToLowerInvariant()).Replace(rootFolder, string.Empty).TrimStart('/'),
73+
pathFilters.All(f => !f.Include))
74+
});
6875

69-
foreach (var pathFilter in pathFilters.OrderBy(pf => pf.Include ? 0 : 1))
76+
return unfilteredResult.Where(f =>
7077
{
71-
foreach (var file in fileIndex)
78+
var include = f.FileInclusion.Include;
79+
foreach (var pathFilter in pathFilters.OrderBy(pf => pf.Include ? 0 : 1))
7280
{
73-
if (pathFilter.Regex.IsMatch(file.Value.Path))
81+
if (pathFilter.Regex.IsMatch(f.FileInclusion.Path))
7482
{
75-
fileIndex[file.Key].Include = pathFilter.Include;
83+
include = pathFilter.Include;
7684
}
7785
}
78-
}
7986

80-
var included = new List<FileInfo>();
81-
foreach (var file in fileIndex)
82-
{
83-
if (file.Value.Include)
87+
if (!include)
8488
{
85-
included.Add(file.Key);
89+
progressMonitor.Log(Severity.Info, $"Excluding '{f.FileInfo.FullName}'");
8690
}
87-
else
88-
{
89-
progressMonitor.Log(Severity.Info, $"Excluding '{file.Key.FullName}'");
90-
}
91-
}
9291

93-
return included;
92+
return include;
93+
}).Select(f => f.FileInfo);
9494
}
9595
}
9696
}

0 commit comments

Comments
 (0)