mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-04-03 06:16:04 +00:00
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:
@@ -198,7 +198,8 @@ void TServer::GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uin
|
||||
int PID = -1;
|
||||
int VID = -1;
|
||||
|
||||
auto MaybePidVid = GetPidVid(StringPacket.substr(3).substr(0, StringPacket.substr(3).find(':', 1)));
|
||||
auto pidVidPart = StringPacket.substr(3);
|
||||
auto MaybePidVid = GetPidVid(pidVidPart.substr(0, pidVidPart.find(':')));
|
||||
if (MaybePidVid) {
|
||||
std::tie(PID, VID) = MaybePidVid.value();
|
||||
}
|
||||
@@ -289,7 +290,8 @@ void TServer::GlobalParser(const std::weak_ptr<TClient>& Client, std::vector<uin
|
||||
int PID = -1;
|
||||
int VID = -1;
|
||||
|
||||
auto MaybePidVid = GetPidVid(StringPacket.substr(3).substr(0, StringPacket.substr(3).find(':', 1)));
|
||||
auto pidVidPart = StringPacket.substr(3);
|
||||
auto MaybePidVid = GetPidVid(pidVidPart.substr(0, pidVidPart.find(':')));
|
||||
if (MaybePidVid) {
|
||||
std::tie(PID, VID) = MaybePidVid.value();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user