summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-04-07 23:46:44 -0500
committerAdam <Adam@anope.org>2013-04-07 23:46:44 -0500
commitfb7fef7a849342ab8463743497e781c5c3e6ae88 (patch)
tree5d230a68b6eed70c7b4f718410dd62fea779654c
parent36602224b8b1a11326a224779d16bcb12f0ed532 (diff)
Optimizations of much of the more commonly used code
-rw-r--r--include/access.h2
-rw-r--r--include/anope.h17
-rw-r--r--include/channels.h19
-rw-r--r--include/hashcomp.h4
-rw-r--r--include/logger.h27
-rw-r--r--include/modes.h29
-rw-r--r--include/protocol.h2
-rw-r--r--include/servers.h8
-rw-r--r--include/users.h4
-rw-r--r--modules/commands/bs_kick.cpp4
-rw-r--r--modules/commands/cs_access.cpp4
-rw-r--r--modules/commands/cs_akick.cpp5
-rw-r--r--modules/commands/cs_ban.cpp3
-rw-r--r--modules/commands/cs_enforce.cpp12
-rw-r--r--modules/commands/cs_kick.cpp3
-rw-r--r--modules/commands/cs_mode.cpp11
-rw-r--r--modules/commands/cs_seen.cpp15
-rw-r--r--modules/commands/cs_set.cpp3
-rw-r--r--modules/commands/cs_suspend.cpp2
-rw-r--r--modules/commands/cs_sync.cpp2
-rw-r--r--modules/commands/cs_updown.cpp15
-rw-r--r--modules/commands/ns_recover.cpp6
-rw-r--r--modules/commands/os_chankill.cpp2
-rw-r--r--modules/commands/os_dns.cpp10
-rw-r--r--modules/commands/os_forbid.cpp62
-rw-r--r--modules/commands/os_forbid.h6
-rw-r--r--modules/commands/os_jupe.cpp2
-rw-r--r--modules/commands/os_list.cpp4
-rw-r--r--modules/commands/os_mode.cpp6
-rw-r--r--modules/commands/os_noop.cpp2
-rw-r--r--modules/commands/os_session.cpp174
-rw-r--r--modules/commands/os_session.h6
-rw-r--r--modules/commands/os_sxline.cpp2
-rw-r--r--modules/extra/cs_statusupdate.cpp4
-rw-r--r--modules/extra/m_xmlrpc_main.cpp4
-rw-r--r--modules/protocol/bahamut.cpp34
-rw-r--r--modules/protocol/charybdis.cpp2
-rw-r--r--modules/protocol/hybrid.cpp30
-rw-r--r--modules/protocol/inspircd11.cpp27
-rw-r--r--modules/protocol/inspircd12.cpp41
-rw-r--r--modules/protocol/inspircd20.cpp6
-rw-r--r--modules/protocol/ngircd.cpp24
-rw-r--r--modules/protocol/plexus.cpp9
-rw-r--r--modules/protocol/ratbox.cpp2
-rw-r--r--modules/protocol/unreal.cpp38
-rw-r--r--modules/pseudoclients/chanserv.cpp4
-rw-r--r--modules/pseudoclients/memoserv.cpp4
-rw-r--r--modules/pseudoclients/nickserv.cpp4
-rw-r--r--modules/pseudoclients/operserv.cpp18
-rw-r--r--src/access.cpp10
-rw-r--r--src/bots.cpp4
-rw-r--r--src/channels.cpp115
-rw-r--r--src/config.cpp11
-rw-r--r--src/hashcomp.cpp80
-rw-r--r--src/logger.cpp209
-rw-r--r--src/main.cpp3
-rw-r--r--src/messages.cpp15
-rw-r--r--src/misc.cpp6
-rw-r--r--src/modes.cpp219
-rw-r--r--src/process.cpp29
-rw-r--r--src/protocol.cpp2
-rw-r--r--src/regchannel.cpp31
-rw-r--r--src/servers.cpp56
-rw-r--r--src/users.cpp24
64 files changed, 752 insertions, 786 deletions
diff --git a/include/access.h b/include/access.h
index ea2667774..f60625ad9 100644
--- a/include/access.h
+++ b/include/access.h
@@ -79,6 +79,8 @@ class CoreExport ChanAccess : public Serializable
AccessProvider *provider;
/* Channel this access entry is on */
Serialize::Reference<ChannelInfo> ci;
+ /* account this access entry is for, if any */
+ Serialize::Reference<NickCore> nc;
Anope::string mask;
Anope::string creator;
time_t last_seen;
diff --git a/include/anope.h b/include/anope.h
index 9bf0f982d..8e24d12da 100644
--- a/include/anope.h
+++ b/include/anope.h
@@ -255,7 +255,7 @@ namespace Anope
{
Anope::string new_string = *this;
for (size_type i = 0; i < new_string.length(); ++i)
- new_string[i] = std::tolower(new_string[i], Anope::casemap);
+ new_string[i] = Anope::tolower(new_string[i]);
return new_string;
}
@@ -266,7 +266,7 @@ namespace Anope
{
Anope::string new_string = *this;
for (size_type i = 0; i < new_string.length(); ++i)
- new_string[i] = std::toupper(new_string[i], Anope::casemap);
+ new_string[i] = Anope::toupper(new_string[i]);
return new_string;
}
@@ -547,15 +547,12 @@ class CoreExport sepstream
/** Original string.
*/
Anope::string tokens;
- /** Last position of a seperator token
- */
- Anope::string::iterator last_starting_position;
- /** Current string position
- */
- Anope::string::iterator n;
/** Seperator value
*/
char sep;
+ /** Current string position
+ */
+ size_t pos;
public:
/** Create a sepstream and fill it with the provided data
*/
@@ -570,7 +567,7 @@ class CoreExport sepstream
/** Gets token number 'num' from the stream
* @param token The token is placed here
* @param num The token number to featch
- * @return True if the token was able to be detched
+ * @return True if the token was able to be fetched
*/
bool GetToken(Anope::string &token, int num);
@@ -588,7 +585,7 @@ class CoreExport sepstream
/** Gets token number 'num' from the stream and all remaining tokens.
* @param token The token is placed here
* @param num The token number to featch
- * @return True if the token was able to be detched
+ * @return True if the token was able to be fetched
*/
bool GetTokenRemainder(Anope::string &token, int num);
diff --git a/include/channels.h b/include/channels.h
index 18ef65a7c..118864c8a 100644
--- a/include/channels.h
+++ b/include/channels.h
@@ -54,7 +54,7 @@ class CoreExport Channel : public Base, public Extensible
time_t creation_time;
/* Users in the channel */
- typedef std::list<ChanUserContainer *> ChanUserList;
+ typedef std::map<User *, ChanUserContainer *> ChanUserList;
ChanUserList users;
/* Current topic of the channel */
@@ -75,12 +75,14 @@ class CoreExport Channel : public Base, public Extensible
int16_t chanserv_modecount; /* Number of check_mode()'s this sec */
int16_t bouncy_modes; /* Did we fail to set modes here? */
+ private:
/** Constructor
* @param name The channel name
* @param ts The time the channel was created
*/
Channel(const Anope::string &nname, time_t ts = Anope::CurTime);
+ public:
/** Destructor
*/
~Channel();
@@ -113,14 +115,14 @@ class CoreExport Channel : public Base, public Extensible
* @param u The user
* @return A user container if found, else NULL
*/
- ChanUserContainer *FindUser(const User *u) const;
+ ChanUserContainer *FindUser(User *u) const;
/** Check if a user has a status on a channel
* @param u The user
* @param cms The status mode, or NULL to represent no status
* @return true or false
*/
- bool HasUserStatus(const User *u, ChannelModeStatus *cms) const;
+ bool HasUserStatus(User *u, ChannelModeStatus *cms);
/** Check if a user has a status on a channel
* Use the overloaded function for ChannelModeStatus* to check for no status
@@ -128,7 +130,7 @@ class CoreExport Channel : public Base, public Extensible
* @param name The mode name, eg CMODE_OP, CMODE_VOICE
* @return true or false
*/
- bool HasUserStatus(const User *u, const Anope::string &name) const;
+ bool HasUserStatus(User *u, const Anope::string &name);
/** See if a channel has a mode
* @param name The mode name
@@ -279,13 +281,20 @@ class CoreExport Channel : public Base, public Extensible
* @param full Whether or not to match using the user's real host and IP
* @return whether or not a ban was removed
*/
- bool Unban(const User *u, bool full = false);
+ bool Unban(User *u, bool full = false);
/** Finds a channel
* @param name The channel to find
* @return The channel, if found
*/
static Channel* Find(const Anope::string &name);
+
+ /** Finds or creates a channel
+ * @param name The channel name
+ * @param created Set to true if the channel was just created
+ * @param ts The time the channel was created
+ */
+ static Channel *FindOrCreate(const Anope::string &name, bool &created, time_t ts = Anope::CurTime);
};
#endif // CHANNELS_H
diff --git a/include/hashcomp.h b/include/hashcomp.h
index 9ebc7ae81..38c0e3833 100644
--- a/include/hashcomp.h
+++ b/include/hashcomp.h
@@ -28,6 +28,10 @@ namespace Anope
/* Casemap in use by Anope. ci::string's comparation functions use this (and thus Anope::string) */
extern std::locale casemap;
+ extern void CaseMapRebuild();
+ extern unsigned char tolower(unsigned char);
+ extern unsigned char toupper(unsigned char);
+
/* ASCII case insensitive ctype. */
template<typename char_type>
class ascii_ctype : public std::ctype<char_type>
diff --git a/include/logger.h b/include/logger.h
index 5050c22ce..afa874ca3 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -45,7 +45,8 @@ struct LogFile
std::ofstream stream;
LogFile(const Anope::string &name);
- Anope::string GetName() const;
+ ~LogFile();
+ const Anope::string &GetName() const;
};
/* Represents a single log message */
@@ -72,7 +73,6 @@ class CoreExport Log
Module *m;
LogType type;
Anope::string category;
- std::list<Anope::string> sources;
std::stringstream buf;
@@ -109,17 +109,18 @@ class CoreExport Log
class CoreExport LogInfo
{
public:
- std::list<Anope::string> targets;
- std::map<Anope::string, LogFile *> logfiles;
- std::list<Anope::string> sources;
+ std::vector<Anope::string> targets;
+ std::vector<LogFile *> logfiles;
+ int last_day;
+ std::vector<Anope::string> sources;
int log_age;
- std::list<Anope::string> admin;
- std::list<Anope::string> override;
- std::list<Anope::string> commands;
- std::list<Anope::string> servers;
- std::list<Anope::string> users;
- std::list<Anope::string> channels;
- std::list<Anope::string> normal;
+ std::vector<Anope::string> admin;
+ std::vector<Anope::string> override;
+ std::vector<Anope::string> commands;
+ std::vector<Anope::string> servers;
+ std::vector<Anope::string> users;
+ std::vector<Anope::string> channels;
+ std::vector<Anope::string> normal;
bool raw_io;
bool debug;
@@ -127,7 +128,7 @@ class CoreExport LogInfo
~LogInfo();
- void AddType(std::list<Anope::string> &list, const Anope::string &type);
+ void OpenLogFiles();
bool HasType(LogType ltype, const Anope::string &type) const;
diff --git a/include/modes.h b/include/modes.h
index bb329b5b4..6a39393bb 100644
--- a/include/modes.h
+++ b/include/modes.h
@@ -134,7 +134,7 @@ class CoreExport ChannelModeList : public ChannelMode
* @param e The entry to match against
* @return true on match
*/
- virtual bool Matches(const User *u, const Entry *e) { return false; }
+ virtual bool Matches(User *u, const Entry *e) { return false; }
/** Called when a mask is added to a channel
* @param chan The channel
@@ -181,7 +181,7 @@ class CoreExport ChannelModeStatus : public ChannelMode
{
public:
/* The symbol, eg @ % + */
- char Symbol;
+ char symbol;
/* The "level" of the mode, used to compare with other modes.
* Used so we know op > halfop > voice etc.
*/
@@ -190,10 +190,10 @@ class CoreExport ChannelModeStatus : public ChannelMode
/** constructor
* @param name The mode name
* @param mc The mode char
- * @param mSymbol The symbol for the mode, eg @ %
+ * @param msymbol The symbol for the mode, eg @ %
* @param mlevel A level for the mode, which is usually determined by the PREFIX capab
*/
- ChannelModeStatus(const Anope::string &name, char mc, char mSymbol, short mlevel = 0);
+ ChannelModeStatus(const Anope::string &name, char mc, char msymbol, short mlevel = 0);
/** destructor
*/
@@ -203,9 +203,14 @@ class CoreExport ChannelModeStatus : public ChannelMode
/* The status a user has on a channel (+v, +h, +o) etc */
class CoreExport ChannelStatus
{
+ Anope::string modes;
public:
- std::set<Anope::string> modes;
- Anope::string BuildCharPrefixList() const;
+ void AddMode(char c);
+ void DelMode(char c);
+ bool HasMode(char c) const;
+ bool Empty() const;
+ void Clear();
+ const Anope::string &Modes() const;
Anope::string BuildModePrefixList() const;
};
@@ -292,11 +297,14 @@ class CoreExport ModeManager
*/
static std::list<Anope::string> BuildModeStrings(StackerInfo *info);
- public:
- /* List of all modes Anope knows about */
+ /* Array of all modes Anope knows about. Modes are in this array at position
+ * modechar. Additionally, status modes are in this array (again) at statuschar.
+ */
static std::vector<ChannelMode *> ChannelModes;
static std::vector<UserMode *> UserModes;
+ public:
+
/* Number of generic channel and user modes we are tracking */
static unsigned GenericChannelModes;
static unsigned GenericUserModes;
@@ -358,6 +366,9 @@ class CoreExport ModeManager
*/
static char GetStatusChar(char symbol);
+ static const std::vector<ChannelMode *> &GetChannelModes();
+ static const std::vector<UserMode *> &GetUserModes();
+
/** Add a mode to the stacker to be set on a channel
* @param bi The client to set the modes from
* @param c The channel
@@ -419,7 +430,7 @@ class CoreExport Entry
* @param full True to match against a users real host and IP
* @return true on match
*/
- bool Matches(const User *u, bool full = false) const;
+ bool Matches(User *u, bool full = false) const;
};
#endif // MODES_H
diff --git a/include/protocol.h b/include/protocol.h
index 8953d25e5..23bed3003 100644
--- a/include/protocol.h
+++ b/include/protocol.h
@@ -148,7 +148,7 @@ class CoreExport IRCDProto : public Service
* be set on the user. This may include the modes in the join, but will usually place them on the mode
* stacker to be set "soon".
*/
- virtual void SendJoin(const User *u, Channel *c, const ChannelStatus *status) = 0;
+ virtual void SendJoin(User *u, Channel *c, const ChannelStatus *status) = 0;
virtual void SendPart(const BotInfo *bi, const Channel *chan, const char *fmt, ...);
/** Force joins a user that isn't ours to a channel.
diff --git a/include/servers.h b/include/servers.h
index d8b01626f..bf0acb523 100644
--- a/include/servers.h
+++ b/include/servers.h
@@ -33,6 +33,10 @@ namespace Servers
*/
extern CoreExport Server* GetUplink();
+ /* Server maps by name and id */
+ extern CoreExport Anope::map<Server *> ByName;
+ extern CoreExport Anope::map<Server *> ByID;
+
/* CAPAB/PROTOCTL given by the uplink */
extern CoreExport std::set<Anope::string> Capab;
}
@@ -169,10 +173,10 @@ class CoreExport Server : public Extensible
/** Find a server
* @param name The name or SID/numeric
- * @param s The server list to search for this server on, defaults to our Uplink
+ * @param name_only set to true to only look up by name, not SID
* @return The server
*/
- static Server *Find(const Anope::string &name, Server *s = NULL);
+ static Server *Find(const Anope::string &name, bool name_only = false);
};
#endif // SERVERS_H
diff --git a/include/users.h b/include/users.h
index 4110ad211..5bcd61f95 100644
--- a/include/users.h
+++ b/include/users.h
@@ -79,7 +79,7 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe
bool super_admin;
/* Channels the user is in */
- typedef std::list<ChanUserContainer *> ChanUserList;
+ typedef std::map<Channel *, ChanUserContainer *> ChanUserList;
ChanUserList chans;
/* Last time this user sent a memo command used */
@@ -312,7 +312,7 @@ class CoreExport User : public virtual Base, public Extensible, public CommandRe
* @param c The channel
* @return The channel container, or NULL
*/
- ChanUserContainer *FindChannel(const Channel *c) const;
+ ChanUserContainer *FindChannel(Channel *c) const;
/** Check if the user is protected from kicks and negative mode changes
* @return true or false
diff --git a/modules/commands/bs_kick.cpp b/modules/commands/bs_kick.cpp
index 3f7cc16c2..97f6b6035 100644
--- a/modules/commands/bs_kick.cpp
+++ b/modules/commands/bs_kick.cpp
@@ -808,7 +808,7 @@ class BSKick : public Module
{
Channel *c = cit->second;
for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it)
- (*it)->Shrink("bs_main_userdata");
+ it->second->Shrink("bs_main_userdata");
c->Shrink("bs_main_bandata");
}
}
@@ -1033,7 +1033,7 @@ class BSKick : public Module
{
for (User::ChanUserList::iterator it = u->chans.begin(); it != u->chans.end();)
{
- Channel *chan = (*it)->chan;
+ Channel *chan = it->second->chan;
++it;
if (chan->ci && chan->ci->HasExt("BS_KICK_AMSGS") && !chan->ci->AccessFor(u).HasPriv("NOKICK"))
diff --git a/modules/commands/cs_access.cpp b/modules/commands/cs_access.cpp
index 239c344ab..3a4bdff54 100644
--- a/modules/commands/cs_access.cpp
+++ b/modules/commands/cs_access.cpp
@@ -326,7 +326,7 @@ class CommandCSAccess : public Command
Anope::string timebuf;
if (ci->c)
for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit)
- if (access->Matches((*cit)->user, (*cit)->user->Account()))
+ if (access->Matches(cit->second->user, cit->second->user->Account()))
timebuf = "Now";
if (timebuf.empty())
{
@@ -360,7 +360,7 @@ class CommandCSAccess : public Command
Anope::string timebuf;
if (ci->c)
for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit)
- if (access->Matches((*cit)->user, (*cit)->user->Account()))
+ if (access->Matches(cit->second->user, cit->second->user->Account()))
timebuf = "Now";
if (timebuf.empty())
{
diff --git a/modules/commands/cs_akick.cpp b/modules/commands/cs_akick.cpp
index a3133b8e9..f2bd603f9 100644
--- a/modules/commands/cs_akick.cpp
+++ b/modules/commands/cs_akick.cpp
@@ -390,9 +390,10 @@ class CommandCSAKick : public Command
return;
}
- for (User::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; )
+ for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; )
{
- ChanUserContainer *uc = *it++;
+ ChanUserContainer *uc = it->second;
+ ++it;
if (ci->CheckKick(uc->user))
++count;
diff --git a/modules/commands/cs_ban.cpp b/modules/commands/cs_ban.cpp
index 06c8de95a..5aad394a3 100644
--- a/modules/commands/cs_ban.cpp
+++ b/modules/commands/cs_ban.cpp
@@ -160,7 +160,8 @@ class CommandCSBan : public Command
int matched = 0, kicked = 0;
for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end;)
{
- ChanUserContainer *uc = *it++;
+ ChanUserContainer *uc = it->second;
+ ++it;
if (Anope::Match(uc->user->nick, target) || Anope::Match(uc->user->GetDisplayedMask(), target))
{
diff --git a/modules/commands/cs_enforce.cpp b/modules/commands/cs_enforce.cpp
index 4d5ba0242..fd5caf613 100644
--- a/modules/commands/cs_enforce.cpp
+++ b/modules/commands/cs_enforce.cpp
@@ -31,7 +31,7 @@ class CommandCSEnforce : public Command
for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it)
{
- ChanUserContainer *uc = *it;
+ ChanUserContainer *uc = it->second;
ci->c->SetCorrectModes(uc->user, false, false);
}
@@ -50,7 +50,7 @@ class CommandCSEnforce : public Command
std::vector<User *> users;
for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it)
{
- ChanUserContainer *uc = *it;
+ ChanUserContainer *uc = it->second;
User *user = uc->user;
if (user->IsProtected())
@@ -81,7 +81,7 @@ class CommandCSEnforce : public Command
std::vector<User *> users;
for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it)
{
- ChanUserContainer *uc = *it;
+ ChanUserContainer *uc = it->second;
User *user = uc->user;
if (user->IsProtected())
@@ -113,7 +113,7 @@ class CommandCSEnforce : public Command
std::vector<User *> users;
for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it)
{
- ChanUserContainer *uc = *it;
+ ChanUserContainer *uc = it->second;
User *user = uc->user;
if (user->IsProtected())
@@ -145,7 +145,7 @@ class CommandCSEnforce : public Command
std::vector<User *> users;
for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it)
{
- ChanUserContainer *uc = *it;
+ ChanUserContainer *uc = it->second;
User *user = uc->user;
if (user->IsProtected())
@@ -195,7 +195,7 @@ class CommandCSEnforce : public Command
/* The newer users are at the end of the list, so kick users starting from the end */
for (Channel::ChanUserList::reverse_iterator it = ci->c->users.rbegin(), it_end = ci->c->users.rend(); it != it_end; ++it)
{
- ChanUserContainer *uc = *it;
+ ChanUserContainer *uc = it->second;
User *user = uc->user;
if (user->IsProtected())
diff --git a/modules/commands/cs_kick.cpp b/modules/commands/cs_kick.cpp
index 03beaf0a8..870c18f0c 100644
--- a/modules/commands/cs_kick.cpp
+++ b/modules/commands/cs_kick.cpp
@@ -79,7 +79,8 @@ class CommandCSKick : public Command
int matched = 0, kicked = 0;
for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end;)
{
- ChanUserContainer *uc = *it++;
+ ChanUserContainer *uc = it->second;
+ ++it;</