From 9c322ab976d05b80df7b2e86281b6531bb85ae25 Mon Sep 17 00:00:00 2001 From: brain Date: Wed, 27 Sep 2006 07:50:43 +0000 Subject: Because the user's prefix list must remain sorted at all times (because of assumptions in xchat) this means that we don't need to scan the list looking for their highest prefix, it will always be at begin(). This changes the speed of GetPrefix() and GetPrefixValue() from O(n) to O(1). git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5348 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/channels.cpp | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/channels.cpp b/src/channels.cpp index 353798e96..5e2ef907c 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -885,26 +885,20 @@ long chanrec::GetMaxBans() */ const char* chanrec::GetPrefixChar(userrec *user) { - static char px[2]; - unsigned int mx = 0; - - *px = 0; - *(px+1) = 0; - + static char pf[2] = {0, 0}; + prefixlist::iterator n = prefixes.find(user); if (n != prefixes.end()) { - for (std::vector::iterator x = n->second.begin(); x != n->second.end(); x++) + if (n->second.size()) { - if (x->second > mx) - { - *px = x->first; - mx = x->second; - } + *pf = n->second.begin()->first; + return pf; } } - return px; + *pf = 0; + return pf; } const char* chanrec::GetAllPrefixChars(userrec* user) @@ -929,19 +923,13 @@ const char* chanrec::GetAllPrefixChars(userrec* user) unsigned int chanrec::GetPrefixValue(userrec* user) { - unsigned int mx = 0; - prefixlist::iterator n = prefixes.find(user); if (n != prefixes.end()) { - for (std::vector::iterator x = n->second.begin(); x != n->second.end(); x++) - { - if (x->second > mx) - mx = x->second; - } + if (n->second.size()) + return n->second.begin()->second; } - - return mx; + return 0; } -- cgit v1.2.3