summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-10-16 17:01:49 +0000
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>2009-10-16 17:01:49 +0000
commit62a1eab66838294f2b88d5ea94c1678c167d6189 (patch)
treeb673ecb572a3dfcb341a97fc72ee38c891b6d5af /src
parent7c55dfc7887b2ca91e4ebdf9f2733de8adb56e18 (diff)
Clean up static allocations
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11878 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/configreader.cpp5
-rw-r--r--src/users.cpp56
2 files changed, 39 insertions, 22 deletions
diff --git a/src/configreader.cpp b/src/configreader.cpp
index 4877cab5a..d1fb5e197 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -816,6 +816,11 @@ static const InitialConfig Values[] = {
{"options", "invitebypassmodes", "1", new ValueContainerBool (&ServerConfig::InvBypassModes), DT_BOOLEAN, NULL},
};
+InitialConfig::~InitialConfig()
+{
+ delete val;
+}
+
/* These tags can occur multiple times, and therefore they have special code to read them
* which is different to the code for reading the singular tags listed above.
*/
diff --git a/src/users.cpp b/src/users.cpp
index 7952c98ac..729213e42 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -11,8 +11,6 @@
* ---------------------------------------------------
*/
-/* $Core */
-
#include "inspircd.h"
#include <stdarg.h>
#include "socketengine.h"
@@ -20,15 +18,37 @@
#include "bancache.h"
#include "commands/cmd_whowas.h"
-static unsigned long uniq_id = 1;
-
-static unsigned long* already_sent = NULL;
-
-void InitializeAlreadySent(SocketEngine* SE)
+typedef unsigned int uniq_id_t;
+class sent
{
- already_sent = new unsigned long[SE->GetMaxFds()];
- memset(already_sent, 0, SE->GetMaxFds() * sizeof(unsigned long));
-}
+ uniq_id_t uniq_id;
+ uniq_id_t* array;
+ void init()
+ {
+ if (!array)
+ array = new uniq_id_t[ServerInstance->SE->GetMaxFds()];
+ memset(array, 0, ServerInstance->SE->GetMaxFds() * sizeof(uniq_id_t));
+ uniq_id++;
+ }
+ public:
+ sent() : uniq_id(static_cast<uniq_id_t>(-1)), array(NULL) {}
+ inline uniq_id_t operator++()
+ {
+ if (++uniq_id == 0)
+ init();
+ return uniq_id;
+ }
+ inline uniq_id_t& operator[](int i)
+ {
+ return array[i];
+ }
+ ~sent()
+ {
+ delete array;
+ }
+};
+
+static sent already_sent;
std::string User::ProcessNoticeMasks(const char *sm)
{
@@ -1234,9 +1254,7 @@ void User::WriteCommonRaw(const std::string &line, bool include_self)
if (this->registered != REG_ALL || quitting)
return;
- if (!already_sent)
- InitializeAlreadySent(ServerInstance->SE);
- uniq_id++;
+ uniq_id_t uniq_id = ++already_sent;
UserChanList include_c(chans);
std::map<User*,bool> exceptions;
@@ -1279,10 +1297,7 @@ void User::WriteCommonQuit(const std::string &normal_text, const std::string &op
if (this->registered != REG_ALL)
return;
- uniq_id++;
-
- if (!already_sent)
- InitializeAlreadySent(ServerInstance->SE);
+ uniq_id_t uniq_id = ++already_sent;
snprintf(tb1,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),normal_text.c_str());
snprintf(tb2,MAXBUF,":%s QUIT :%s",this->GetFullHost().c_str(),oper_text.c_str());
@@ -1401,11 +1416,8 @@ void User::DoHostCycle(const std::string &quitline)
if (!ServerInstance->Config->CycleHosts)
return;
- unsigned int silent_id = ++uniq_id;
- unsigned int seen_id = ++uniq_id;
-
- if (!already_sent)
- InitializeAlreadySent(ServerInstance->SE);
+ uniq_id_t silent_id = ++already_sent;
+ uniq_id_t seen_id = ++already_sent;
UserChanList include_c(chans);
std::map<User*,bool> exceptions;