aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorGravatar Daniel De Graaf2010-04-13 12:47:42 -0500
committerGravatar Daniel De Graaf2010-08-03 17:32:42 -0400
commitc1a07677db2bb0b023d5eb3565353cb0843eefbf (patch)
tree5d2bae34ba9d411ce19e9179498d289b1d2c468d /include
parentFix "foo" < "foobar" comparison in irc::string (diff)
Change UserChanList to an intrusive-style linked list
Diffstat (limited to 'include')
-rw-r--r--include/membership.h51
-rw-r--r--include/modules.h2
-rw-r--r--include/typedefs.h9
-rw-r--r--include/users.h1
4 files changed, 53 insertions, 10 deletions
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<User*,bool> &exceptions);
+ virtual void OnBuildNeighborList(User* source, std::vector<Channel*> &include_c, std::map<User*,bool> &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<irc::string, time_t> > InvitedList;
*/
typedef std::vector<reference<ConnectClass> > ClassVector;
-/** Typedef for the list of user-channel records for a user
- */
-typedef std::set<Channel*> UserChanList;
-
-/** Shorthand for an iterator into a UserChanList
- */
-typedef UserChanList::iterator UCListIter;
-
/** A list of custom modes parameters on a channel
*/
typedef std::map<ModeID,std::string> 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
*/