サブパスのリスト(行)をList<FileInfo>
と比較し、リストに欠損エントリを追加する以下の方法があります。_missingImageFolderEnteries
私はLINQを使用しており、処理が驚くほど遅いように見えます。どのようにアイデアを考えているのか、パフォーマンスを改善する方法を考えていますか?おそらくLINQはここにはありませんが、私は標準的なループよりも効率的でなければならないと考えました。FileInfoのリストと比較したサブパス文字列のリスト
private List<FileInfo> _imageFilesInFolderPathList = new List<FileInfo>();
private readonly List<Tuple<string, string>> _missingImageFolderEnteries = new List<Tuple<string, string>>();
private void CrossCheckImageWithFolder(EnumerableRowCollection<DataRow> Rows)
{
foreach (var dr in Rows)
{
var filepath = dr[ImagePathHeader].ToString();
if (!_imageFilesInFolderPathList.Any(row =>
row.FullName.EndsWith(FilePathHandler.FormatSubPath(filepath))))
_missingImageFolderEnteries.Add(
new Tuple<string, string>(
filepath.Substring(CommonInitFolder.Length).StartsWith("\\")
? filepath.Substring(CommonInitFolder.Length)
: "\\" + filepath.Substring(CommonInitFolder.Length),
" does not exist in image folder"));
}
_missingImageFolderEnteries.Sort((x, y) => y.Item1.CompareTo(x.Item1));
}
public static string FormatSubPath(string path, bool needsSlash = true)
{
var returnPath = path;
if (returnPath.StartsWith("."))
returnPath = returnPath.Substring(1);
if (!returnPath.StartsWith("\\") && needsSlash)
returnPath = "\\" + returnPath;
else if (returnPath.StartsWith("\\") && !needsSlash)
returnPath = returnPath.Substring(1);
return returnPath;
}
_「標準ループよりも効率的でなければならないと思った」_ LINQはループを隠すだけです。実際には、古典的なループよりもLINQで非効率なコードを書く方が簡単です。しかし、LINQを使って効率的なコードを書くことができます。 –