Reduce allocations for checking file write time

FileInfo inherits from FileSystemInfo, which initializes a bunch of
strings that we don't need
this isn't a great optimization, just a fun exercise finding a quicker
approach to get these values
This commit is contained in:
Kurt 2019-04-05 18:45:59 -07:00
parent 054d498619
commit 2f2512b09c
3 changed files with 5 additions and 5 deletions

View file

@ -88,7 +88,7 @@ namespace PKHeX.Core
}
// return newest save file path that is valid
var byMostRecent = possiblePaths.OrderByDescending(f => new FileInfo(f).LastWriteTime);
var byMostRecent = possiblePaths.OrderByDescending(File.GetLastWriteTimeUtc);
var saves = byMostRecent.Select(SaveUtil.GetVariantSAV);
return saves.FirstOrDefault(z => z?.ChecksumsValid == true);
}
@ -116,7 +116,7 @@ namespace PKHeX.Core
if (!result)
return Enumerable.Empty<SaveFile>();
var byMostRecent = possiblePaths.OrderByDescending(f => new FileInfo(f).LastWriteTime);
var byMostRecent = possiblePaths.OrderByDescending(File.GetLastWriteTimeUtc);
return byMostRecent.Select(SaveUtil.GetVariantSAV);
}

View file

@ -647,13 +647,13 @@ namespace PKHeX.WinForms
var deleted = 0;
var db = RawDB.Where(pk => pk.Identifier.StartsWith(DatabasePath + Path.DirectorySeparatorChar, StringComparison.Ordinal))
.OrderByDescending(file => new FileInfo(file.Identifier).LastWriteTime);
.OrderByDescending(file => File.GetLastWriteTimeUtc(file.Identifier));
var clones = SearchUtil.GetExtraClones(db);
foreach (var pk in clones)
{
try { File.Delete(pk.Identifier); ++deleted; }
catch { WinFormsUtil.Error(MsgDBDeleteCloneFail + Environment.NewLine + pk.Identifier); }
catch (Exception ex) { WinFormsUtil.Error(MsgDBDeleteCloneFail + Environment.NewLine + ex.Message + Environment.NewLine + pk.Identifier); }
}
if (deleted == 0)

View file

@ -228,7 +228,7 @@ namespace PKHeX.WinForms
public GameVersion Game => Save.Version;
public string Played => Save.PlayTimeString.PadLeft(9, '0');
public string FileTime => new FileInfo(Save.FilePath).LastWriteTime.ToString("yyyy.MM.dd:hh:mm:ss");
public string FileTime => File.GetLastWriteTimeUtc(Save.FilePath).ToString("yyyy.MM.dd:hh:mm:ss");
public string TID => Save.Generation >= 7 ? Save.TrainerID7.ToString("000000") : Save.TID.ToString("00000");
public string SID => Save.Generation >= 7 ? Save.TrainerSID7.ToString("0000") : Save.SID.ToString("00000");