mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 10:46:33 +02:00
[PTRun]Optimize loop gathering results and memory consumption in WindowWalker (#31188)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Plugin.WindowWalker.Properties;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Plugin;
|
||||
@@ -22,33 +23,23 @@ namespace Microsoft.Plugin.WindowWalker.Components
|
||||
/// <returns>List of results</returns>
|
||||
internal static List<Result> GetResultList(List<SearchResult> searchControllerResults, bool isKeywordSearch, string icon, string infoIcon)
|
||||
{
|
||||
bool addExplorerInfo = false;
|
||||
List<Result> resultsList = new List<Result>();
|
||||
|
||||
foreach (SearchResult x in searchControllerResults)
|
||||
if (searchControllerResults == null || searchControllerResults.Count == 0)
|
||||
{
|
||||
if (string.Equals(x.Result.Process.Name, "explorer.exe", StringComparison.OrdinalIgnoreCase) && x.Result.Process.IsShellProcess)
|
||||
{
|
||||
addExplorerInfo = true;
|
||||
}
|
||||
|
||||
resultsList.Add(new Result()
|
||||
{
|
||||
Title = x.Result.Title,
|
||||
IcoPath = icon,
|
||||
SubTitle = GetSubtitle(x.Result),
|
||||
ContextData = x.Result,
|
||||
Action = c =>
|
||||
{
|
||||
x.Result.SwitchToWindow();
|
||||
return true;
|
||||
},
|
||||
|
||||
// For debugging you can set the second parameter to true to see more information.
|
||||
ToolTipData = GetToolTip(x.Result, false),
|
||||
});
|
||||
return new List<Result>();
|
||||
}
|
||||
|
||||
List<Result> resultsList = new List<Result>(searchControllerResults.Count);
|
||||
bool addExplorerInfo = searchControllerResults.Any(x =>
|
||||
string.Equals(x.Result.Process.Name, "explorer.exe", StringComparison.OrdinalIgnoreCase) &&
|
||||
x.Result.Process.IsShellProcess);
|
||||
|
||||
// Process each SearchResult to convert it into a Result.
|
||||
// Using parallel processing if the operation is CPU-bound and the list is large.
|
||||
resultsList = searchControllerResults
|
||||
.AsParallel()
|
||||
.Select(x => CreateResultFromSearchResult(x, icon))
|
||||
.ToList();
|
||||
|
||||
if (addExplorerInfo && isKeywordSearch && !WindowWalkerSettings.Instance.HideExplorerSettingInfo)
|
||||
{
|
||||
resultsList.Add(GetExplorerInfoResult(infoIcon));
|
||||
@@ -57,6 +48,31 @@ namespace Microsoft.Plugin.WindowWalker.Components
|
||||
return resultsList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a Result object from a given SearchResult.
|
||||
/// </summary>
|
||||
/// <param name="searchResult">The SearchResult object to convert.</param>
|
||||
/// <param name="icon">The path to the icon that should be used for the Result.</param>
|
||||
/// <returns>A Result object populated with data from the SearchResult.</returns>
|
||||
private static Result CreateResultFromSearchResult(SearchResult searchResult, string icon)
|
||||
{
|
||||
return new Result
|
||||
{
|
||||
Title = searchResult.Result.Title,
|
||||
IcoPath = icon,
|
||||
SubTitle = GetSubtitle(searchResult.Result),
|
||||
ContextData = searchResult.Result,
|
||||
Action = c =>
|
||||
{
|
||||
searchResult.Result.SwitchToWindow();
|
||||
return true;
|
||||
},
|
||||
|
||||
// For debugging you can set the second parameter to true to see more information.
|
||||
ToolTipData = GetToolTip(searchResult.Result, false),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the subtitle for a result
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user