Use SearchOption.AllDirectories and EnumerateFiles

Avoids unnecessary allocations (arrays and LINQ) and allows enumerating
through the results immediately without having to wait for arrays to be
allocated, filled, and returned.
This commit is contained in:
Justin Van Patten
2014-08-01 11:22:13 -07:00
parent 6ca03325d6
commit 9e2f93f809

View File

@@ -23,18 +23,14 @@ namespace Squirrel
{
Contract.Requires(rootPath != null);
return rootPath.GetDirectories()
.SelectMany(GetAllFilesRecursively)
.Concat(rootPath.GetFiles());
return rootPath.EnumerateFiles("*", SearchOption.AllDirectories);
}
public static IEnumerable<string> GetAllFilePathsRecursively(string rootPath)
{
Contract.Requires(rootPath != null);
return Directory.GetDirectories(rootPath)
.SelectMany(GetAllFilePathsRecursively)
.Concat(Directory.GetFiles(rootPath));
return Directory.EnumerateFiles(rootPath, "*", SearchOption.AllDirectories);
}
public static string CalculateFileSHA1(string filePath)