Skip to content

Commit

Permalink
perf: ⚡ create static empty List<Result> for reuse (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNZL committed Jul 6, 2023
1 parent 65f6ebb commit 6172c8e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace Flow.Launcher.Plugin.TogglTrack
/// </summary>
public class Main : IAsyncPlugin, ISettingProvider
{
internal readonly static List<Result> NoResults = new List<Result>();

private static SettingsViewModel? _viewModel;
private PluginInitContext? _context;
private Settings? _settings;
Expand Down
10 changes: 5 additions & 5 deletions src/TogglTrack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ private async ValueTask<List<Result>> _GetStartResults(CancellationToken token,
this._state.ResultsSource = (TogglTrack.ExclusiveResultsSource.Start, true);

this._context.API.ChangeQuery($"{query.ActionKeyword} {query.Search}", true);
return new List<Result>();
return Main.NoResults;
}

var projects = new List<Result>();
Expand Down Expand Up @@ -1060,7 +1060,7 @@ private async ValueTask<List<Result>> _GetStartResults(CancellationToken token,
bool escapeIfEmpty = (this._state.SelectedIds.Project != -1);

this._context.API.ChangeQuery($"{query.ActionKeyword} {((escapeIfEmpty) ? $"{Settings.EscapeCharacter} " : string.Empty)}");
return new List<Result>();
return Main.NoResults;
}
else if (this._settings.ShowUsageTips && !string.IsNullOrEmpty(query.Search))
{
Expand Down Expand Up @@ -1574,7 +1574,7 @@ private async ValueTask<List<Result>> _GetContinueResults(CancellationToken toke
{
if (string.IsNullOrEmpty(query.Search))
{
return new List<Result>();
return Main.NoResults;
}

var me = (await this._GetMe(token))?.ToMe();
Expand All @@ -1586,7 +1586,7 @@ private async ValueTask<List<Result>> _GetContinueResults(CancellationToken toke
var timeEntries = (await this._GetMaxReportTimeEntries(token))?.ToSummaryReport(me);
if (timeEntries is null)
{
return new List<Result>();
return Main.NoResults;
}

string entriesQuery = new TransformedQuery(query)
Expand Down Expand Up @@ -1827,7 +1827,7 @@ private async ValueTask<List<Result>> _GetEditResults(CancellationToken token, Q
.ToString();

this._context.API.ChangeQuery($"{query.ActionKeyword} {queryToDescription} ");
return new List<Result>();
return Main.NoResults;
}
else if (this._settings.ShowUsageTips)
{
Expand Down

0 comments on commit 6172c8e

Please sign in to comment.