refactor: optimize string operations and improve code clarity

- Avoid redundant substr() calls in packet parsing hot-path (TServer.cpp)
  The previous code called substr(3) twice per packet, creating
  unnecessary temporary strings. Now stores the result once.

- Replace .size() == 0 with .empty() for idiomatic C++
  (TConsole.cpp, TLuaEngine.cpp)
This commit is contained in:
Kipstz
2025-12-24 03:04:24 +01:00
parent 420c64f6cf
commit b74f0c7ca8
3 changed files with 9 additions and 7 deletions
+4 -4
View File
@@ -160,7 +160,7 @@ void TConsole::ChangeToRegularConsole() {
}
bool TConsole::EnsureArgsCount(const std::vector<std::string>& args, size_t n) {
if (n == 0 && args.size() != 0) {
if (n == 0 && !args.empty()) {
Application::Console().WriteRaw("This command expects no arguments.");
return false;
} else if (args.size() != n) {
@@ -198,7 +198,7 @@ void TConsole::Command_Lua(const std::string&, const std::vector<std::string>& a
} else {
Application::Console().WriteRaw("Lua state '" + NewStateId + "' is not a known state. Didn't switch to Lua.");
}
} else if (args.size() == 0) {
} else if (args.empty()) {
ChangeToLuaConsole(mDefaultStateId);
}
}
@@ -423,7 +423,7 @@ void TConsole::Command_Settings(const std::string&, const std::vector<std::strin
settings set <category> <setting> <value> sets specified setting to value
)";
if (args.size() == 0) {
if (args.empty()) {
beammp_errorf("No arguments specified for command 'settings'!");
Application::Console().WriteRaw("BeamMP-Server Console: " + std::string(sHelpString));
return;
@@ -705,7 +705,7 @@ void TConsole::RunAsCommand(const std::string& cmd, bool IgnoreNotACommand) {
}
}
}
if (NonNilFutures.size() == 0) {
if (NonNilFutures.empty()) {
if (!IgnoreNotACommand) {
Application::Console().WriteRaw("Error: Unknown command: '" + cmd + "'. Type 'help' to see a list of valid commands.");
}