summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-31 22:50:56 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-31 22:50:56 +0000
commit74b5dabce28ef513118142ae1856fce1f53b5a95 (patch)
tree228f8a7e56c9aa89f9df0cf1d23418cb5d0b6320
parent3eb54dca416a658380a2395da46afff2e8b4d453 (diff)
Made CountChannels faster. We use it in quite a few places. It's now O(1) rather than O(n)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5094 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/users.h10
-rw-r--r--src/channels.cpp2
-rw-r--r--src/users.cpp12
3 files changed, 21 insertions, 3 deletions
diff --git a/include/users.h b/include/users.h
index 9a4057f88..4633f1cd2 100644
--- a/include/users.h
+++ b/include/users.h
@@ -171,6 +171,10 @@ class userrec : public connection
* channels are removed from this list.
*/
InvitedList invites;
+
+ /** Number of channels this user is currently on
+ */
+ unsigned int ChannelCount;
public:
/** Resolvers for looking up this users IP address
* This will occur if and when res_reverse completes.
@@ -718,6 +722,12 @@ class userrec : public connection
*/
int CountChannels();
+ /** Modify the number of channels this user is on (used by CountChannels).
+ * Pass a positive number to increment the counter, or a negative number
+ * to decrement it.
+ */
+ void ModChannelCount(int n);
+
/** Send a notice to all local users from this user
* @param text The text format string to send
* @param ... Format arguments
diff --git a/src/channels.cpp b/src/channels.cpp
index f340e12bf..5c3bb266f 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -425,6 +425,7 @@ chanrec* chanrec::ForceChan(InspIRCd* Instance, chanrec* Ptr,ucrec *a,userrec* u
a->channel = Ptr;
Ptr->AddUser(user);
+ user->ModChannelCount(1);
Ptr->WriteChannel(user,"JOIN :%s",Ptr->name);
/* Major improvement by Brain - we dont need to be calculating all this pointlessly for remote users */
@@ -467,6 +468,7 @@ long chanrec::PartUser(userrec *user, const char* reason)
}
user->chans[i]->uc_modes = 0;
user->chans[i]->channel = NULL;
+ user->ModChannelCount(-1);
this->RemoveAllPrefixes(user);
break;
}
diff --git a/src/users.cpp b/src/users.cpp
index 46f5d512b..c98518d2f 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -272,7 +272,7 @@ userrec::userrec(InspIRCd* Instance) : ServerInstance(Instance)
server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName);
reset_due = ServerInstance->Time();
lines_in = lastping = signon = idle_lastmsg = nping = registered = 0;
- timeout = flood = bytes_in = bytes_out = cmds_in = cmds_out = 0;
+ ChannelCount = timeout = flood = bytes_in = bytes_out = cmds_in = cmds_out = 0;
haspassed = dns_done = false;
fd = -1;
recvq = "";
@@ -1609,11 +1609,17 @@ bool userrec::SharesChannelWith(userrec *other)
int userrec::CountChannels()
{
- int z = 0;
+ return ChannelCount;
+ /*int z = 0;
for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
if ((*i)->channel)
z++;
- return z;
+ return z;*/
+}
+
+void userrec::ModChannelCount(int n)
+{
+ ChannelCount += n;
}
bool userrec::ChangeName(const char* gecos)