From e56629542168c203cac8504085fc96c7f7b73d90 Mon Sep 17 00:00:00 2001 From: Petr Bena Date: Wed, 23 Sep 2015 16:07:16 +0200 Subject: [PATCH] Performance tweak: rem. pointless recursive calls For some reason there was an extra call to IrcChannel::joinIrcUser from IrcUser::joinIrcChannel. That means that in past we did: * Call to IrcChannel::joinIrcUsers(...) * From there we call IrcUser::joinIrcChannel(this) * And from there we called IrcChannel::joinIrcUser(this) * Which again called IrcChannel::joinIrcUsers(list that contained only this 1 user) * Which figured out this user is already in this channel and exits That is a pointless overhead, so now we call the second function with extra parameter that tells it not to call joinIrcUser because we know this user doesn't need to be added there, thus saves few thousands of pointless function calls and user list contructions, especially while joining large channels. --- src/common/ircchannel.cpp | 2 +- src/common/ircuser.cpp | 5 +++-- src/common/ircuser.h | 7 ++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/common/ircchannel.cpp b/src/common/ircchannel.cpp index 53e495a0..c111b9fa 100644 --- a/src/common/ircchannel.cpp +++ b/src/common/ircchannel.cpp @@ -183,7 +183,7 @@ void IrcChannel::joinIrcUsers(const QList &users, const QStringList & } _userModes[ircuser] = modes[i]; - ircuser->joinChannel(this); + ircuser->joinChannel(this, true); connect(ircuser, SIGNAL(nickSet(QString)), this, SLOT(ircUserNickSet(QString))); // connect(ircuser, SIGNAL(destroyed()), this, SLOT(ircUserDestroyed())); diff --git a/src/common/ircuser.cpp b/src/common/ircuser.cpp index 543f2b71..32ff7944 100644 --- a/src/common/ircuser.cpp +++ b/src/common/ircuser.cpp @@ -275,12 +275,13 @@ void IrcUser::updateHostmask(const QString &mask) } -void IrcUser::joinChannel(IrcChannel *channel) +void IrcUser::joinChannel(IrcChannel *channel, bool skip_channel_join) { Q_ASSERT(channel); if (!_channels.contains(channel)) { _channels.insert(channel); - channel->joinIrcUser(this); + if (!skip_channel_join) + channel->joinIrcUser(this); } } diff --git a/src/common/ircuser.h b/src/common/ircuser.h index c8840ed8..c33a3b2d 100644 --- a/src/common/ircuser.h +++ b/src/common/ircuser.h @@ -118,7 +118,12 @@ public slots: void setUserModes(const QString &modes); - void joinChannel(IrcChannel *channel); + /*! + * \brief joinChannel Called when user joins some channel, this function inserts the channel to internal list of channels this user is in. + * \param channel Pointer to a channel this user just joined + * \param skip_channel_join If this is false, this function will also call IrcChannel::joinIrcUser, can be set to true as a performance tweak. + */ + void joinChannel(IrcChannel *channel, bool skip_channel_join = false); void joinChannel(const QString &channelname); void partChannel(IrcChannel *channel); void partChannel(const QString &channelname); -- 2.20.1