Skip to content

Commit

Permalink
Small perf tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
FenPhoenix committed Jul 11, 2019
1 parent cf7fea2 commit 64d4041
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
13 changes: 8 additions & 5 deletions AngelLoader/Common/Utility/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions AngelLoader/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> 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<string>());
}
}

Expand Down
11 changes: 10 additions & 1 deletion AngelLoader/FMCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
6 changes: 1 addition & 5 deletions AngelLoader/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions AngelLoader/Forms/MainForm_InitManual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 64d4041

Please sign in to comment.