diff options
author | w00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-07-19 20:34:14 +0000 |
---|---|---|
committer | w00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7> | 2008-07-19 20:34:14 +0000 |
commit | a67b9de1742efbff29ec08093b220565eab7df23 (patch) | |
tree | 1f0778b8e417fd24873b945f8d2e89a292a25942 | |
parent | e93827e41cdb958314eb669e94c9dd1280b691c9 (diff) |
Change modes in channels and users to use std::bitset instead of an array. This saves 56 bytes per channel, and 112 bytes per channel, with no loss in speed or ease of use in code. :). Thanks (VERY) much to Special for telling me about this.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10043 e03df62e-2008-0410-955e-edbf42e46eb7
-rwxr-xr-x | configure | 2 | ||||
-rw-r--r-- | include/channels.h | 4 | ||||
-rw-r--r-- | include/configreader.h | 1 | ||||
-rw-r--r-- | include/globals.h | 37 | ||||
-rw-r--r-- | include/inspircd.h | 28 | ||||
-rw-r--r-- | include/modules.h | 1 | ||||
-rw-r--r-- | include/socketengines/socketengine_epoll.h | 1 | ||||
-rw-r--r-- | include/socketengines/socketengine_iocp.h | 1 | ||||
-rw-r--r-- | include/socketengines/socketengine_kqueue.h | 1 | ||||
-rw-r--r-- | include/socketengines/socketengine_ports.h | 1 | ||||
-rw-r--r-- | include/socketengines/socketengine_select.h | 1 | ||||
-rw-r--r-- | include/users.h | 12 | ||||
-rw-r--r-- | src/modes/umode_n.cpp | 2 | ||||
-rw-r--r-- | src/users.cpp | 2 |
14 files changed, 35 insertions, 59 deletions
@@ -1728,7 +1728,7 @@ ITEM # now print the command file details. foreach my $cmd (@cmdlist) { print FH <<ITEM; -cmd_$cmd.so: cmd_$cmd.cpp ../../include/base.h ../../include/modules.h ../../include/inspircd.h ../../include/channels.h ../../include/users.h ../../include/globals.h ../../include/inspircd_config.h ../../include/commands/cmd_$cmd.h +cmd_$cmd.so: cmd_$cmd.cpp ../../include/base.h ../../include/modules.h ../../include/inspircd.h ../../include/channels.h ../../include/users.h ../../include/inspircd_config.h ../../include/commands/cmd_$cmd.h \@../../make/run-cc.pl \$(CC) -pipe -I../../include \$(FLAGS) -export-dynamic $SHARED -o cmd_$cmd.so cmd_$cmd.cpp ITEM diff --git a/include/channels.h b/include/channels.h index 0d4c4813c..2042df220 100644 --- a/include/channels.h +++ b/include/channels.h @@ -137,12 +137,12 @@ class CoreExport Channel : public Extensible std::string name; /* CHANMAX */ /** Modes for the channel. - * This is not a null terminated string! It is a hash where + * This is not a null terminated string! It is a bitset where * each item in it represents if a mode is set. For example * for mode +A, index 0. Use modechar-65 to calculate which * field to check. */ - unsigned char modes[64]; + std::bitset<64> modes; /** User lists. * There are four user lists, one for diff --git a/include/configreader.h b/include/configreader.h index 7a753bcc7..51eb2f5fd 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -26,7 +26,6 @@ #include <vector> #include <map> #include "inspircd.h" -#include "globals.h" #include "modules.h" #include "socketengine.h" #include "socket.h" diff --git a/include/globals.h b/include/globals.h deleted file mode 100644 index 2de2ba11b..000000000 --- a/include/globals.h +++ /dev/null @@ -1,37 +0,0 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ - * - * InspIRCd: (C) 2002-2008 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits - * - * This program is free but copyrighted software; see - * the file COPYING for details. - * - * --------------------------------------------------- - */ - -#ifndef __WORLD_H -#define __WORLD_H - -#include <vector> -#include <deque> -#include <map> - -/** A cached text file stored with its contents as lines - */ -typedef std::deque< std::string > file_cache; - -/** A configuration key and value pair - */ -typedef std::pair< std::string, std::string > KeyVal; - -/** A list of related configuration keys and values - */ -typedef std::vector< KeyVal > KeyValList; - -/** An entire config file, built up of KeyValLists - */ -typedef std::multimap< std::string, KeyValList > ConfigDataHash; - -#endif diff --git a/include/inspircd.h b/include/inspircd.h index 9ef5dbcfb..a225c7e3a 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -38,6 +38,31 @@ #include <cmath> #include <cstring> #include <climits> +#include <vector> +#include <deque> +#include <map> +#include <bitset> + + +/** A list of failed port bindings, used for informational purposes on startup */ +typedef std::vector<std::pair<std::string, std::string> > FailedPortList; + +/** A cached text file stored with its contents as lines + */ +typedef std::deque< std::string > file_cache; + +/** A configuration key and value pair + */ +typedef std::pair< std::string, std::string > KeyVal; + +/** A list of related configuration keys and values + */ +typedef std::vector< KeyVal > KeyValList; + +/** An entire config file, built up of KeyValLists + */ +typedef std::multimap< std::string, KeyValList > ConfigDataHash; + #include "inspircd_config.h" #include "numerics.h" @@ -234,9 +259,6 @@ class serverstats : public classbase } }; -/** A list of failed port bindings, used for informational purposes on startup */ -typedef std::vector<std::pair<std::string, std::string> > FailedPortList; - class InspIRCd; DEFINE_HANDLER1(ProcessUserHandler, void, User*); diff --git a/include/modules.h b/include/modules.h index 7945a33ad..772f4ab5f 100644 --- a/include/modules.h +++ b/include/modules.h @@ -14,7 +14,6 @@ #ifndef __MODULES_H #define __MODULES_H -#include "globals.h" #include "dynamic.h" #include "base.h" #include "ctables.h" diff --git a/include/socketengines/socketengine_epoll.h b/include/socketengines/socketengine_epoll.h index 07d0e3621..517f93d2e 100644 --- a/include/socketengines/socketengine_epoll.h +++ b/include/socketengines/socketengine_epoll.h @@ -18,7 +18,6 @@ #include <string> #include <map> #include "inspircd_config.h" -#include "globals.h" #include "inspircd.h" #include "socketengine.h" #include <sys/epoll.h> diff --git a/include/socketengines/socketengine_iocp.h b/include/socketengines/socketengine_iocp.h index 845228967..80689017c 100644 --- a/include/socketengines/socketengine_iocp.h +++ b/include/socketengines/socketengine_iocp.h @@ -19,7 +19,6 @@ #include "inspircd_config.h" #include "inspircd_win32wrapper.h" -#include "globals.h" #include "inspircd.h" #include "socketengine.h" diff --git a/include/socketengines/socketengine_kqueue.h b/include/socketengines/socketengine_kqueue.h index 49b51590a..14664918a 100644 --- a/include/socketengines/socketengine_kqueue.h +++ b/include/socketengines/socketengine_kqueue.h @@ -18,7 +18,6 @@ #include <string> #include <map> #include "inspircd_config.h" -#include "globals.h" #include "inspircd.h" #include <sys/types.h> #include <sys/event.h> diff --git a/include/socketengines/socketengine_ports.h b/include/socketengines/socketengine_ports.h index 519eaad8b..0b0655fb0 100644 --- a/include/socketengines/socketengine_ports.h +++ b/include/socketengines/socketengine_ports.h @@ -22,7 +22,6 @@ #include <string> #include <map> #include "inspircd_config.h" -#include "globals.h" #include "inspircd.h" #include "socketengine.h" #include <port.h> diff --git a/include/socketengines/socketengine_select.h b/include/socketengines/socketengine_select.h index cb4ed0ecf..91746b252 100644 --- a/include/socketengines/socketengine_select.h +++ b/include/socketengines/socketengine_select.h @@ -21,7 +21,6 @@ #include <sys/select.h> #endif // WINDOWS #include "inspircd_config.h" -#include "globals.h" #include "inspircd.h" #include "socketengine.h" diff --git a/include/users.h b/include/users.h index 39abc6309..503a1e568 100644 --- a/include/users.h +++ b/include/users.h @@ -17,7 +17,6 @@ #include "socket.h" #include "connection.h" #include "dns.h" - #include "mode.h" /** Channel status for a user @@ -534,20 +533,21 @@ class CoreExport User : public connection std::string fullname; /** The user's mode list. - * This is NOT a null terminated string! In the 1.1 version of InspIRCd - * this is an array of values in a similar way to channel modes. - * A value of 1 in field (modeletter-65) indicates that the mode is + * NOT a null terminated string. + * Also NOT an array. + * Much love to the STL for giving us an easy to use bitset, saving us RAM. + * if (modes[modeletter-65]) is set, then the mode is * set, for example, to work out if mode +s is set, we check the field * User::modes['s'-65] != 0. * The following RFC characters o, w, s, i have constants defined via an * enum, such as UM_SERVERNOTICE and UM_OPETATOR. */ - unsigned char modes[64]; + std::bitset<64> modes; /** What snomasks are set on this user. * This functions the same as the above modes. */ - unsigned char snomasks[64]; + std::bitset<64> snomasks; /** Channels this user is on, and the permissions they have there */ diff --git a/src/modes/umode_n.cpp b/src/modes/umode_n.cpp index ed08b60f4..ee3fe09b3 100644 --- a/src/modes/umode_n.cpp +++ b/src/modes/umode_n.cpp @@ -32,7 +32,7 @@ ModeAction ModeUserServerNoticeMask::OnModeChange(User* source, User* dest, Chan { /* Fix for bug #310 reported by Smartys */ if (!dest->modes[UM_SNOMASK]) - memset(dest->snomasks, 0, sizeof(dest->snomasks)); + dest->snomasks.reset(); parameter = dest->ProcessNoticeMasks(parameter.c_str()); dest->modes[UM_SNOMASK] = true; diff --git a/src/users.cpp b/src/users.cpp index a0ed42446..3e9baba72 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -205,8 +205,6 @@ User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance AllowedOperCommands = NULL; chans.clear(); invites.clear(); - memset(modes,0,sizeof(modes)); - memset(snomasks,0,sizeof(snomasks)); if (uid.empty()) uuid.assign(Instance->GetUID(), 0, UUID_LENGTH - 1); |