Improve performance in the Completion module (#2288)

Only resort the data entries when we modify the lists. Also use EncodeWithNullTerminator to ensure the safety of strings.

Also avoid parsing the category names when we're only looking for the presence of the Dalamud category
This commit is contained in:
salanth357 2025-05-31 07:24:28 -04:00 committed by GitHub
parent a2f6fb85e5
commit e2609bbe0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -202,7 +202,7 @@ internal sealed unsafe class Completion : IInternalDisposableService
for (var i = 0; i < module->CategoryNames.Count; i++)
{
if (module->CategoryNames[i].ExtractText() == "【Dalamud】")
if (module->CategoryNames[i].AsReadOnlySeStringSpan().ContainsText("【Dalamud】"u8))
{
return module->CategoryData[i];
}
@ -248,17 +248,24 @@ internal sealed unsafe class Completion : IInternalDisposableService
if (catData->CompletionData.Count == 0)
{
var inputCommands = this.commandManager.Commands.Where(pair => pair.Value.ShowInHelp).OrderBy(pair => pair.Key);
var inputCommands = this.commandManager.Commands.Where(pair => pair.Value.ShowInHelp);
foreach (var (cmd, _) in inputCommands)
AddEntry(cmd);
catData->SortEntries();
return;
}
var needsSort = false;
while (this.addedCommands.TryDequeue(out var cmd))
{
needsSort = true;
AddEntry(cmd);
}
if (needsSort)
catData->SortEntries();
catData->SortEntries();
return;
void AddEntry(string cmd)
@ -302,7 +309,7 @@ internal sealed unsafe class Completion : IInternalDisposableService
private class EntryStrings(string command) : IDisposable
{
public Utf8String* Display { get; } =
Utf8String.FromSequence(new SeStringBuilder().AddUiForeground(command, 539).Encode());
Utf8String.FromSequence(new SeStringBuilder().AddUiForeground(command, 539).BuiltString.EncodeWithNullTerminator());
public Utf8String* Match { get; } = Utf8String.FromString(command);