From c1a07677db2bb0b023d5eb3565353cb0843eefbf Mon Sep 17 00:00:00 2001 From: Daniel De Graaf Date: Tue, 13 Apr 2010 12:47:42 -0500 Subject: Change UserChanList to an intrusive-style linked list --- include/membership.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- include/modules.h | 2 +- include/typedefs.h | 9 +-------- include/users.h | 1 + 4 files changed, 53 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/membership.h b/include/membership.h index 4ddb644dc..21e3a5a5f 100644 --- a/include/membership.h +++ b/include/membership.h @@ -16,17 +16,66 @@ class CoreExport Membership : public Extensible { + Membership* u_prev; + Membership* u_next; public: User* const user; Channel* const chan; // mode list, sorted by prefix rank, higest first std::string modes; - Membership(User* u, Channel* c) : user(u), chan(c) {} + Membership(User* u, Channel* c) : u_prev(NULL), u_next(NULL), user(u), chan(c) {} inline bool hasMode(char m) const { return modes.find(m) != std::string::npos; } unsigned int getRank(); + friend class UCListIter; + friend class UserChanList; +}; + +class CoreExport UCListIter +{ + Membership* curr; + public: + UCListIter(Membership* i) : curr(i) {} + inline void operator++() { if (curr) curr = curr->u_next; } + inline void operator++(int) { if (curr) curr = curr->u_next; } + inline bool operator==(const UCListIter& o) const { return curr == o.curr; } + inline bool operator!=(const UCListIter& o) const { return curr != o.curr; } + inline Membership* operator->() const { return curr; } + inline Membership& operator*() const { return *curr; } +}; + +class CoreExport UserChanList : public interfacebase +{ + Membership* head; + size_t siz; + public: + UserChanList() : head(NULL), siz(0) {} + inline UCListIter begin() { return head; } + inline UCListIter end() { return NULL; } + inline void insert(Membership* m) + { + siz++; + if (head) + { + m->u_next = head; + head->u_prev = m; + } + head = m; + } + inline void erase(Membership* m) + { + siz--; + if (head == m) + head = m->u_next; + if (m->u_next) + m->u_next->u_prev = m->u_prev; + if (m->u_prev) + m->u_prev->u_next = m->u_next; + m->u_prev = m->u_next = NULL; + } + inline size_t size() { return siz; } }; #endif diff --git a/include/modules.h b/include/modules.h index b827adefd..0f98b9986 100644 --- a/include/modules.h +++ b/include/modules.h @@ -652,7 +652,7 @@ class CoreExport Module : public classbase, public usecountbase * * Set exceptions[user] = true to include, exceptions[user] = false to exclude */ - virtual void OnBuildNeighborList(User* source, UserChanList &include_c, std::map &exceptions); + virtual void OnBuildNeighborList(User* source, std::vector &include_c, std::map &exceptions); /** Called before any nickchange, local or remote. This can be used to implement Q-lines etc. * Please note that although you can see remote nickchanges through this function, you should diff --git a/include/typedefs.h b/include/typedefs.h index a7c2f7e5c..0284d64f3 100644 --- a/include/typedefs.h +++ b/include/typedefs.h @@ -38,6 +38,7 @@ class StreamSocket; class SyncTarget; class Thread; class User; +class UserChanList; class UserResolver; class XLine; class XLineManager; @@ -73,14 +74,6 @@ typedef std::vector< std::pair > InvitedList; */ typedef std::vector > ClassVector; -/** Typedef for the list of user-channel records for a user - */ -typedef std::set UserChanList; - -/** Shorthand for an iterator into a UserChanList - */ -typedef UserChanList::iterator UCListIter; - /** A list of custom modes parameters on a channel */ typedef std::map CustomModeList; diff --git a/include/users.h b/include/users.h index 8918c8c58..d8623cede 100644 --- a/include/users.h +++ b/include/users.h @@ -18,6 +18,7 @@ #include "inspsocket.h" #include "dns.h" #include "mode.h" +#include "membership.h" /** connect class types */ -- cgit v1.3.1-10-gc9f91