perf(commanddata): take commandName directly instead of re-parsing FullCommand
Constructor previously rebuilt CommandName from FullCommand via substring + Split, allocating on every command invocation despite the caller already holding a clean commandName. Pass it through directly.
This commit is contained in:
@@ -25,7 +25,7 @@ public static class ChatCommandApiPatch
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
var sender = args.Caller.Player as IServerPlayer;
|
var sender = args.Caller.Player as IServerPlayer;
|
||||||
var data = new CommandData(sender, "/" + commandName);
|
var data = new CommandData(sender, commandName, "/" + commandName);
|
||||||
|
|
||||||
if (system.FireBefore(commandName, ref data))
|
if (system.FireBefore(commandName, ref data))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ public struct CommandData
|
|||||||
set => flags = value ? (byte)(flags | FlagCancel) : (byte)(flags & ~FlagCancel);
|
set => flags = value ? (byte)(flags | FlagCancel) : (byte)(flags & ~FlagCancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommandData(IServerPlayer? sender, string fullCommand)
|
public CommandData(IServerPlayer? sender, string commandName, string fullCommand)
|
||||||
{
|
{
|
||||||
Sender = sender;
|
Sender = sender;
|
||||||
FullCommand = fullCommand.Length > 0 ? fullCommand.Trim() : string.Empty;
|
CommandName = commandName;
|
||||||
CommandName = FullCommand.Length > 1 ? FullCommand[1..].Split(' ')[0] : string.Empty;
|
FullCommand = fullCommand;
|
||||||
flags = sender != null ? FlagIsPlayerCommand : (byte)0;
|
flags = sender != null ? FlagIsPlayerCommand : (byte)0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user