Remove Result comparison and Change signature from IEnumerable to ICollection (due to the potential of multiple enumeration)

This commit is contained in:
Hongtao Zhang 2024-12-06 23:55:20 -06:00 committed by VictoriousRaptor
parent 3d8cf29c8e
commit 51a16cc40f
2 changed files with 3 additions and 24 deletions

View file

@ -157,27 +157,6 @@ namespace Flow.Launcher.Plugin
}
}
/// <inheritdoc />
public override bool Equals(object obj)
{
var r = obj as Result;
var equality = string.Equals(r?.Title, Title) &&
string.Equals(r?.SubTitle, SubTitle) &&
string.Equals(r?.AutoCompleteText, AutoCompleteText) &&
string.Equals(r?.CopyText, CopyText) &&
string.Equals(r?.IcoPath, IcoPath) &&
TitleHighlightData == r.TitleHighlightData;
return equality;
}
/// <inheritdoc />
public override int GetHashCode()
{
return HashCode.Combine(Title, SubTitle, AutoCompleteText, CopyText, IcoPath);
}
/// <inheritdoc />
public override string ToString()
{

View file

@ -182,7 +182,7 @@ namespace Flow.Launcher.ViewModel
/// <summary>
/// To avoid deadlock, this method should not called from main thread
/// </summary>
public void AddResults(IEnumerable<ResultsForUpdate> resultsForUpdates, CancellationToken token, bool reselect = true)
public void AddResults(ICollection<ResultsForUpdate> resultsForUpdates, CancellationToken token, bool reselect = true)
{
var newResults = NewResults(resultsForUpdates);
@ -228,12 +228,12 @@ namespace Flow.Launcher.ViewModel
.ToList();
}
private List<ResultViewModel> NewResults(IEnumerable<ResultsForUpdate> resultsForUpdates)
private List<ResultViewModel> NewResults(ICollection<ResultsForUpdate> resultsForUpdates)
{
if (!resultsForUpdates.Any())
return Results;
return Results.Where(r => r != null && !resultsForUpdates.Any(u => u.ID == r.Result.PluginID))
return Results.Where(r => r != null && resultsForUpdates.All(u => u.ID != r.Result.PluginID))
.Concat(resultsForUpdates.SelectMany(u => u.Results, (u, r) => new ResultViewModel(r, _settings)))
.OrderByDescending(rv => rv.Result.Score)
.ToList();