]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Remove a few unneeded string copies in the PRIVMSG path
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 2 Sep 2009 00:45:29 +0000 (00:45 +0000)
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 2 Sep 2009 00:45:29 +0000 (00:45 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11606 e03df62e-2008-0410-955e-edbf42e46eb7

include/channels.h
include/users.h
src/channels.cpp
src/users.cpp

index 220c56cf9532720620ac3e29e0d7637577c64707..9b4bfb1a58fc9b77220a8cac49ef866b40f67ec7 100644 (file)
@@ -425,6 +425,8 @@ class CoreExport Channel : public Extensible
         * @param text A std::string containing the output line without prefix
         */
        void WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string& text);
+       /** Write a line of text that already includes the source */
+       void RawWriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string& text);
 
        /** Returns the maximum number of bans allowed to be set on this channel
         * @return The maximum number of bans allowed
index de4d21f9a0c93fe77201fdf397df577f9ec2bd90..9023d7728b24cbc9f6f6e22aa5fb485c90317ede 100644 (file)
@@ -767,7 +767,7 @@ class CoreExport User : public EventHandler
        /** Write text to this user, appending CR/LF.
         * @param text A std::string to send to the user
         */
-       void Write(std::string text);
+       void Write(const std::string &text);
 
        /** Write text to this user, appending CR/LF.
         * @param text The format string for text to send to the user
index 532953db3489e47a19089feb61f0373035298019..eb4f802f0fee5b5a97c31a40b91c65118edc3254 100644 (file)
@@ -770,21 +770,28 @@ void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList
        if (!text)
                return;
 
+       int offset = snprintf(textbuffer,MAXBUF,":%s ", user->GetFullHost().c_str());
+
        va_start(argsPtr, text);
-       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
+       vsnprintf(textbuffer + offset, MAXBUF - offset, text, argsPtr);
        va_end(argsPtr);
 
-       this->WriteAllExcept(user, serversource, status, except_list, std::string(textbuffer));
+       this->RawWriteAllExcept(user, serversource, status, except_list, std::string(textbuffer));
 }
 
 void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &text)
 {
-       CUList *ulist = this->GetUsers();
        char tb[MAXBUF];
 
-       snprintf(tb,MAXBUF,":%s %s", user->GetFullHost().c_str(), text.c_str());
+       snprintf(tb,MAXBUF,":%s %s", serversource ? ServerInstance->Config->ServerName : user->GetFullHost().c_str(), text.c_str());
        std::string out = tb;
 
+       this->RawWriteAllExcept(user, serversource, status, except_list, std::string(tb));
+}
+
+void Channel::RawWriteAllExcept(User* user, bool serversource, char status, CUList &except_list, const std::string &out)
+{
+       CUList *ulist = this->GetUsers();
        for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
        {
                if ((IS_LOCAL(i->first)) && (except_list.find(i->first) == except_list.end()))
@@ -793,10 +800,7 @@ void Channel::WriteAllExcept(User* user, bool serversource, char status, CUList
                        if (status && !strchr(this->GetAllPrefixChars(i->first), status))
                                continue;
 
-                       if (serversource)
-                               i->first->WriteServ(text);
-                       else
-                               i->first->Write(out);
+                       i->first->Write(out);
                }
        }
 }
index f8fabd4a226afaf56279691b9b5c7f1163733fde..cd5aa247ec23bd399f25dfa9ecabf7941f113d8d 100644 (file)
@@ -1195,27 +1195,12 @@ bool User::SetClientIP(const char* sip)
        return irc::sockets::aptosa(sip, 0, &client_sa);
 }
 
-/** NOTE: We cannot pass a const reference to this method.
- * The string is changed by the workings of the method,
- * so that if we pass const ref, we end up copying it to
- * something we can change anyway. Makes sense to just let
- * the compiler do that copy for us.
- */
-void User::Write(std::string text)
+void User::Write(const std::string& text)
 {
        if (!ServerInstance->SE->BoundsCheckFd(this))
                return;
 
-       try
-       {
-               ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"C[%d] O %s", this->GetFd(), text.c_str());
-               text.append("\r\n");
-       }
-       catch (...)
-       {
-               ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"Exception in User::Write() std::string::append");
-               return;
-       }
+       ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"C[%d] O %s", this->GetFd(), text.c_str());
 
        if (this->GetIOHook())
        {
@@ -1225,6 +1210,7 @@ void User::Write(std::string text)
                try
                {
                        this->GetIOHook()->OnRawSocketWrite(this->fd, text.data(), text.length());
+                       this->GetIOHook()->OnRawSocketWrite(this->fd, "\r\n", 2);
                }
                catch (CoreException& modexcept)
                {
@@ -1234,8 +1220,9 @@ void User::Write(std::string text)
        else
        {
                this->AddWriteBuf(text);
+               this->AddWriteBuf("\r\n");
        }
-       ServerInstance->stats->statsSent += text.length();
+       ServerInstance->stats->statsSent += text.length() + 2;
        this->ServerInstance->SE->WantWrite(this);
 }
 
@@ -1255,10 +1242,7 @@ void User::Write(const char *text, ...)
 
 void User::WriteServ(const std::string& text)
 {
-       char textbuffer[MAXBUF];
-
-       snprintf(textbuffer,MAXBUF,":%s %s",ServerInstance->Config->ServerName,text.c_str());
-       this->Write(std::string(textbuffer));
+       this->Write(":%s %s",ServerInstance->Config->ServerName,text.c_str());
 }
 
 /** WriteServ()