mirror of https://github.com/AxioDL/metaforce.git
Console: Use emplace in registerCommand()
Allows avoiding a redundant initial element. We can also remove the const from the std::function rvalue to allow a std::move to take effect. We can also use the std::string_view constructor for std::string to avoid an unnecessary strlen() call.
This commit is contained in:
parent
cbd40382bf
commit
5d2987588b
|
@ -81,7 +81,7 @@ private:
|
||||||
public:
|
public:
|
||||||
Console(CVarManager*);
|
Console(CVarManager*);
|
||||||
void registerCommand(std::string_view name, std::string_view helpText, std::string_view usage,
|
void registerCommand(std::string_view name, std::string_view helpText, std::string_view usage,
|
||||||
const std::function<void(Console*, const std::vector<std::string>&)>&& func,
|
std::function<void(Console*, const std::vector<std::string>&)>&& func,
|
||||||
SConsoleCommand::ECommandFlags cmdFlags = SConsoleCommand::ECommandFlags::Normal);
|
SConsoleCommand::ECommandFlags cmdFlags = SConsoleCommand::ECommandFlags::Normal);
|
||||||
void unregisterCommand(std::string_view name);
|
void unregisterCommand(std::string_view name);
|
||||||
|
|
||||||
|
|
|
@ -40,12 +40,17 @@ Console::Console(CVarManager* cvarMgr) : m_cvarMgr(cvarMgr), m_overwrite(false),
|
||||||
}
|
}
|
||||||
|
|
||||||
void Console::registerCommand(std::string_view name, std::string_view helpText, std::string_view usage,
|
void Console::registerCommand(std::string_view name, std::string_view helpText, std::string_view usage,
|
||||||
const std::function<void(Console*, const std::vector<std::string>&)>&& func,
|
std::function<void(Console*, const std::vector<std::string>&)>&& func,
|
||||||
SConsoleCommand::ECommandFlags cmdFlags) {
|
SConsoleCommand::ECommandFlags cmdFlags) {
|
||||||
std::string lowName = name.data();
|
std::string lowName{name};
|
||||||
athena::utility::tolower(lowName);
|
athena::utility::tolower(lowName);
|
||||||
if (m_commands.find(lowName) == m_commands.end())
|
|
||||||
m_commands[lowName] = SConsoleCommand{name.data(), helpText.data(), usage.data(), std::move(func), cmdFlags};
|
if (m_commands.find(lowName) != m_commands.end()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_commands.emplace(std::move(lowName), SConsoleCommand{std::string{name}, std::string{helpText}, std::string{usage},
|
||||||
|
std::move(func), cmdFlags});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Console::unregisterCommand(std::string_view name) {
|
void Console::unregisterCommand(std::string_view name) {
|
||||||
|
|
Loading…
Reference in New Issue