summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDylan Frank <b00mx0r@aureus.pw>2018-04-08 20:41:04 -0700
committerPeter Powell <petpow@saberuk.com>2018-04-09 04:41:04 +0100
commit93fa544b2671b078cf81ac04fbb4b48d5e2d1677 (patch)
treebd4f0aaf637a95e00fff5702a5d4bb341b71a61d /src
parent1155320da0ba4454f028b30bc0fb5313e33946b3 (diff)
Optimize some behaviour in the core (#1476).
Diffstat (limited to 'src')
-rw-r--r--src/coremods/core_channel/cmd_names.cpp2
-rw-r--r--src/inspsocket.cpp2
-rw-r--r--src/users.cpp17
3 files changed, 12 insertions, 9 deletions
diff --git a/src/coremods/core_channel/cmd_names.cpp b/src/coremods/core_channel/cmd_names.cpp
index dd2926c33..92f0810de 100644
--- a/src/coremods/core_channel/cmd_names.cpp
+++ b/src/coremods/core_channel/cmd_names.cpp
@@ -36,7 +36,7 @@ CmdResult CommandNames::HandleLocal(const std::vector<std::string>& parameters,
{
Channel* c;
- if (!parameters.size())
+ if (parameters.empty())
{
user->WriteNumeric(RPL_ENDOFNAMES, '*', "End of /NAMES list.");
return CMD_SUCCESS;
diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp
index 709ad443b..42e2640a6 100644
--- a/src/inspsocket.cpp
+++ b/src/inspsocket.cpp
@@ -293,7 +293,7 @@ void StreamSocket::FlushSendQ(SendQueue& sq)
const SendQueue::Element& elem = *i;
iovecs[j].iov_base = const_cast<char*>(elem.data());
iovecs[j].iov_len = elem.length();
- rv_max += elem.length();
+ rv_max += iovecs[j].iov_len;
}
rv = SocketEngine::WriteV(this, iovecs, bufcount);
}
diff --git a/src/users.cpp b/src/users.cpp
index 7f56994d4..5f31ff299 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -645,8 +645,8 @@ bool User::ChangeNick(const std::string& newnick, time_t newts)
}
if (this->registered == REG_ALL)
- this->WriteCommon("NICK %s",newnick.c_str());
- std::string oldnick = nick;
+ this->WriteCommon("NICK %s", newnick.c_str());
+ const std::string oldnick = nick;
nick = newnick;
InvalidateCache();
@@ -767,10 +767,12 @@ void LocalUser::Write(const std::string& text)
if (!SocketEngine::BoundsCheckFd(&eh))
return;
- if (text.length() > ServerInstance->Config->Limits.MaxLine - 2)
+ // The maximum size of an IRC message minus the terminating CR+LF.
+ const size_t maxmessage = ServerInstance->Config->Limits.MaxLine - 2;
+ if (text.length() > maxmessage)
{
- // this should happen rarely or never. Crop the string at 512 and try again.
- std::string try_again(text, 0, ServerInstance->Config->Limits.MaxLine - 2);
+ // This should happen rarely or never. Crop the string at MaxLine and try again.
+ std::string try_again(text, 0, maxmessage);
Write(try_again);
return;
}
@@ -780,8 +782,9 @@ void LocalUser::Write(const std::string& text)
eh.AddWriteBuf(text);
eh.AddWriteBuf(wide_newline);
- ServerInstance->stats.Sent += text.length() + 2;
- this->bytes_out += text.length() + 2;
+ const size_t bytessent = text.length() + 2;
+ ServerInstance->stats.Sent += bytessent;
+ this->bytes_out += bytessent;
this->cmds_out++;
}