From a67b9de1742efbff29ec08093b220565eab7df23 Mon Sep 17 00:00:00 2001 From: w00t Date: Sat, 19 Jul 2008 20:34:14 +0000 Subject: 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 --- configure | 2 +- include/channels.h | 4 ++-- include/configreader.h | 1 - include/globals.h | 37 ----------------------------- include/inspircd.h | 28 +++++++++++++++++++--- include/modules.h | 1 - include/socketengines/socketengine_epoll.h | 1 - include/socketengines/socketengine_iocp.h | 1 - include/socketengines/socketengine_kqueue.h | 1 - include/socketengines/socketengine_ports.h | 1 - include/socketengines/socketengine_select.h | 1 - include/users.h | 12 +++++----- src/modes/umode_n.cpp | 2 +- src/users.cpp | 2 -- 14 files changed, 35 insertions(+), 59 deletions(-) delete mode 100644 include/globals.h diff --git a/configure b/configure index 272698f96..e03739820 100755 --- a/configure +++ b/configure @@ -1728,7 +1728,7 @@ ITEM # now print the command file details. foreach my $cmd (@cmdlist) { print FH < 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 #include #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 -#include -#include - -/** 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 #include #include +#include +#include +#include +#include + + +/** A list of failed port bindings, used for informational purposes on startup */ +typedef std::vector > 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 > 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 #include #include "inspircd_config.h" -#include "globals.h" #include "inspircd.h" #include "socketengine.h" #include 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 #include #include "inspircd_config.h" -#include "globals.h" #include "inspircd.h" #include #include 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 #include #include "inspircd_config.h" -#include "globals.h" #include "inspircd.h" #include "socketengine.h" #include 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 #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); -- cgit v1.2.3