mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
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:
parent
a2f6fb85e5
commit
e2609bbe0c
1 changed files with 11 additions and 4 deletions
|
|
@ -202,7 +202,7 @@ internal sealed unsafe class Completion : IInternalDisposableService
|
||||||
|
|
||||||
for (var i = 0; i < module->CategoryNames.Count; i++)
|
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];
|
return module->CategoryData[i];
|
||||||
}
|
}
|
||||||
|
|
@ -248,17 +248,24 @@ internal sealed unsafe class Completion : IInternalDisposableService
|
||||||
|
|
||||||
if (catData->CompletionData.Count == 0)
|
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)
|
foreach (var (cmd, _) in inputCommands)
|
||||||
AddEntry(cmd);
|
AddEntry(cmd);
|
||||||
|
catData->SortEntries();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var needsSort = false;
|
||||||
while (this.addedCommands.TryDequeue(out var cmd))
|
while (this.addedCommands.TryDequeue(out var cmd))
|
||||||
|
{
|
||||||
|
needsSort = true;
|
||||||
AddEntry(cmd);
|
AddEntry(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (needsSort)
|
||||||
|
catData->SortEntries();
|
||||||
|
|
||||||
catData->SortEntries();
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
void AddEntry(string cmd)
|
void AddEntry(string cmd)
|
||||||
|
|
@ -302,7 +309,7 @@ internal sealed unsafe class Completion : IInternalDisposableService
|
||||||
private class EntryStrings(string command) : IDisposable
|
private class EntryStrings(string command) : IDisposable
|
||||||
{
|
{
|
||||||
public Utf8String* Display { get; } =
|
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);
|
public Utf8String* Match { get; } = Utf8String.FromString(command);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue