From 64d4041d04aa432b941f5c0ccc71ddca7795ec9c Mon Sep 17 00:00:00 2001 From: FenPhoenix Date: Thu, 11 Jul 2019 06:57:49 -0700 Subject: [PATCH] Small perf tweaks --- AngelLoader/Common/Utility/Extensions.cs | 13 ++++++++----- AngelLoader/Core.cs | 11 +++++------ AngelLoader/FMCache.cs | 11 ++++++++++- AngelLoader/Forms/MainForm.cs | 6 +----- AngelLoader/Forms/MainForm_InitManual.cs | 9 ++++----- 5 files changed, 28 insertions(+), 22 deletions(-) diff --git a/AngelLoader/Common/Utility/Extensions.cs b/AngelLoader/Common/Utility/Extensions.cs index afa041f4a..4d0ec1d94 100644 --- a/AngelLoader/Common/Utility/Extensions.cs +++ b/AngelLoader/Common/Utility/Extensions.cs @@ -109,11 +109,14 @@ internal static bool Contains(this string[] value, string substring, StringCompa internal static bool IsValidReadme(this string value) { - return value.ExtIsTxt() || - value.ExtIsRtf() || - value.ExtIsWri() || - value.ExtIsGlml() || - value.ExtIsHtml(); + // Well, this is embarrassing... Apparently EndsWithI is faster than the baked-in ones. + // Dunno how that could be the case, but whatever... + return value.EndsWithI(".txt") || + value.EndsWithI(".rtf") || + value.EndsWithI(".wri") || + value.EndsWithI(".glml") || + value.EndsWithI(".html") || + value.EndsWithI(".htm"); } #region Baked-in extension checks diff --git a/AngelLoader/Core.cs b/AngelLoader/Core.cs index e197909e3..9ff08de1b 100644 --- a/AngelLoader/Core.cs +++ b/AngelLoader/Core.cs @@ -1205,23 +1205,22 @@ internal static bool RemoveDML(FanMission fm, string dmlFile) return true; } - internal static (bool Success, string[] DMLFiles) + internal static (bool Success, List DMLFiles) GetDMLFiles(FanMission fm) { try { - var dmlFiles = - FastIO.GetFilesTopOnly(Path.Combine(GetFMInstallsBasePath(fm.Game), fm.InstalledDir), "*.dml"); + var dmlFiles = FastIO.GetFilesTopOnly(Path.Combine(GetFMInstallsBasePath(fm.Game), fm.InstalledDir), "*.dml"); for (int i = 0; i < dmlFiles.Count; i++) { - dmlFiles[i] = Path.GetFileName(dmlFiles[i]); + dmlFiles[i] = dmlFiles[i].GetFileNameFast(); } - return (true, dmlFiles.ToArray()); + return (true, dmlFiles); } catch (Exception ex) { Log("Exception getting DML files for " + fm.InstalledDir + ", game: " + fm.Game, ex); - return (false, new string[] { }); + return (false, new List()); } } diff --git a/AngelLoader/FMCache.cs b/AngelLoader/FMCache.cs index e7181c850..63f94e8f5 100644 --- a/AngelLoader/FMCache.cs +++ b/AngelLoader/FMCache.cs @@ -120,7 +120,16 @@ internal static CacheData GetCacheableDataInFMInstalledDir(FanMission fm) foreach (var f in files) { - if (f.IsValidReadme()) readmes.Add(f.Substring(path.Length + 1)); + // Calling them manually right from within this loop is like a billion times faster somehow. Meh? + if (f.EndsWithI(".txt") || + f.EndsWithI(".rtf") || + f.EndsWithI(".wri") || + f.EndsWithI(".glml") || + f.EndsWithI(".html") || + f.EndsWithI(".htm")) + { + readmes.Add(f.Substring(path.Length + 1)); + } } return new CacheData { Readmes = readmes }; diff --git a/AngelLoader/Forms/MainForm.cs b/AngelLoader/Forms/MainForm.cs index f1f6181b0..964248d66 100644 --- a/AngelLoader/Forms/MainForm.cs +++ b/AngelLoader/Forms/MainForm.cs @@ -1000,9 +1000,6 @@ public void SetUITextToLocalized(bool suspendResume = true) InstallUninstallFMButton.Text = sayInstall ? LText.MainButtons.InstallFM : LText.MainButtons.UninstallFM; - InstallUninstallFMButton.Image = sayInstall - ? Resources.Install_24 - : Resources.Uninstall_24; InstallUninstallFMButton.ResumeDrawing(); @@ -2793,8 +2790,7 @@ private async Task DisplaySelectedFM(bool refreshReadme = false) { foreach (var f in dmlFiles) { - if (f.IsEmpty()) continue; - PatchDMLsListBox.Items.Add(f); + if (!f.IsEmpty()) PatchDMLsListBox.Items.Add(f); } } } diff --git a/AngelLoader/Forms/MainForm_InitManual.cs b/AngelLoader/Forms/MainForm_InitManual.cs index ad7816fd2..7bae10473 100644 --- a/AngelLoader/Forms/MainForm_InitManual.cs +++ b/AngelLoader/Forms/MainForm_InitManual.cs @@ -17,17 +17,17 @@ they currently work and I'm not 100% certain which one I should keep. Lowest pri */ #if DEBUG || Release_Testing - private readonly System.Diagnostics.Stopwatch t = new System.Diagnostics.Stopwatch(); + private readonly System.Diagnostics.Stopwatch initT = new System.Diagnostics.Stopwatch(); private void StartTimer() { - t.Restart(); + initT.Restart(); } private void StopTimer() { - t.Stop(); - System.Diagnostics.Trace.WriteLine(nameof(InitComponentManual) + "up to stop point: " + t.Elapsed); + initT.Stop(); + System.Diagnostics.Trace.WriteLine(nameof(InitComponentManual) + "up to stop point: " + initT.Elapsed); System.Environment.Exit(1); } #endif @@ -320,7 +320,6 @@ private void InitComponentManual() // InstallUninstallFMButton // InstallUninstallFMButton.AutoSize = true; - InstallUninstallFMButton.Image = Resources.Install_24; InstallUninstallFMButton.ImageAlign = ContentAlignment.MiddleLeft; InstallUninstallFMButton.Padding = new Padding(6, 0, 6, 0); InstallUninstallFMButton.Height = 36;