Skip to content

Commit 955b863

Browse files
Performance: Use Lazy<T> for ShellFolder instances
1 parent 848e2b2 commit 955b863

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Files.App/Helpers/Win32/Win32Helper.Shell.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ namespace Files.App.Helpers
1313
/// </summary>
1414
public static partial class Win32Helper
1515
{
16-
private readonly static ShellFolder _controlPanel = new(Shell32.KNOWNFOLDERID.FOLDERID_ControlPanelFolder);
16+
private readonly static Lazy<ShellFolder> _controlPanel = new(() => new(Shell32.KNOWNFOLDERID.FOLDERID_ControlPanelFolder));
1717

18-
private readonly static ShellFolder _controlPanelCategoryView = new("::{26EE0668-A00A-44D7-9371-BEB064C98683}");
18+
private readonly static Lazy<ShellFolder> _controlPanelCategoryView = new(() => new("::{26EE0668-A00A-44D7-9371-BEB064C98683}"));
1919

2020
public static async Task<(ShellFileItem Folder, List<ShellFileItem> Enumerate)> GetShellFolderAsync(string path, bool getFolder, bool getEnumerate, int from, int count, params string[] properties)
2121
{
@@ -34,8 +34,8 @@ public static partial class Win32Helper
3434
using var shellFolder = ShellFolderExtensions.GetShellItemFromPathOrPIDL(path) as ShellFolder;
3535

3636
if (shellFolder is null ||
37-
(_controlPanel.PIDL.IsParentOf(shellFolder.PIDL, false) ||
38-
_controlPanelCategoryView.PIDL.IsParentOf(shellFolder.PIDL, false)) &&
37+
(_controlPanel.Value.PIDL.IsParentOf(shellFolder.PIDL, false) ||
38+
_controlPanelCategoryView.Value.PIDL.IsParentOf(shellFolder.PIDL, false)) &&
3939
!shellFolder.Any())
4040
{
4141
// Return null to force open unsupported items in explorer

0 commit comments

Comments
 (0)