From 0a8b0d317ed4adc43185c1b791bcf752115dc58e Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Thu, 16 May 2013 20:33:46 +0200 Subject: Remove unused variables, avoid copies where possible, check empty() instead of size() == 0 Most of these were detected by cppcheck --- include/command_parse.h | 10 ---------- include/modules.h | 2 +- 2 files changed, 1 insertion(+), 11 deletions(-) (limited to 'include') diff --git a/include/command_parse.h b/include/command_parse.h index f6ff588e1..f9e3a740c 100644 --- a/include/command_parse.h +++ b/include/command_parse.h @@ -23,10 +23,6 @@ #ifndef COMMAND_PARSE_H #define COMMAND_PARSE_H -/** A list of dll/so files containing the command handlers for the core - */ -typedef std::map SharedObjectList; - /** This class handles command management and parsing. * It allows you to add and remove commands from the map, * call command handlers by name, and chop up comma seperated @@ -35,10 +31,6 @@ typedef std::map SharedObjectList; class CoreExport CommandParser { private: - /** Parameter buffer - */ - std::vector para; - /** Process a parameter string into a list of items * @param command_p The output list of items * @param parameters The input string @@ -52,8 +44,6 @@ class CoreExport CommandParser */ bool ProcessCommand(LocalUser *user, std::string &cmd); - - public: /** Command list, a hash_map of command names to Command* */ diff --git a/include/modules.h b/include/modules.h index 8aedaabdd..00f2cbb62 100644 --- a/include/modules.h +++ b/include/modules.h @@ -116,7 +116,7 @@ struct ModResult { * and numerical comparisons in preprocessor macros if they wish to support * multiple versions of InspIRCd in one file. */ -#define INSPIRCD_VERSION_API 5 +#define INSPIRCD_VERSION_API 6 /** * This #define allows us to call a method in all -- cgit v1.3.1-10-gc9f91 From bb962f92ace6eb23c66c5fccee01f825c22363c3 Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Thu, 16 May 2013 20:51:12 +0200 Subject: Workaround for std::list::size() having linear complexity on some implementations --- include/usermanager.h | 6 +++++- src/usermanager.cpp | 3 ++- src/users.cpp | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/usermanager.h b/include/usermanager.h index 3d7fe88fb..743db508a 100644 --- a/include/usermanager.h +++ b/include/usermanager.h @@ -63,7 +63,11 @@ class CoreExport UserManager /** Number of unregistered users online right now. * (Unregistered means before USER/NICK/dns) */ - int unregistered_count; + unsigned int unregistered_count; + + /** Number of elements in local_users + */ + unsigned int local_count; /** Map of global ip addresses for clone counting * XXX - this should be private, but m_clones depends on it currently. diff --git a/src/usermanager.cpp b/src/usermanager.cpp index e3ddfc9f2..670add777 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -74,6 +74,7 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs ServerInstance->Users->AddGlobalClone(New); New->localuseriter = this->local_users.insert(local_users.end(), New); + local_count++; if ((this->local_users.size() > ServerInstance->Config->SoftLimit) || (this->local_users.size() >= (unsigned int)ServerInstance->SE->GetMaxFds())) { @@ -332,7 +333,7 @@ unsigned int UserManager::UnregisteredUserCount() unsigned int UserManager::LocalUserCount() { /* Doesnt count unregistered clients */ - return (this->local_users.size() - this->UnregisteredUserCount()); + return (this->local_count - this->UnregisteredUserCount()); } void UserManager::ServerNoticeAll(const char* text, ...) diff --git a/src/users.cpp b/src/users.cpp index f48e3642f..2305ba8ce 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -545,7 +545,10 @@ CullResult LocalUser::cull() // overwritten in UserManager::AddUser() with the real iterator so this check // is only a precaution currently. if (localuseriter != ServerInstance->Users->local_users.end()) + { + ServerInstance->Users->local_count--; ServerInstance->Users->local_users.erase(localuseriter); + } else ServerInstance->Logs->Log("USERS", DEFAULT, "ERROR: LocalUserIter does not point to a valid entry for " + this->nick); -- cgit v1.3.1-10-gc9f91 From 67822c67e91e70917ddbdec0bd8453c7170ee06d Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Sat, 18 May 2013 16:03:17 +0200 Subject: Initialize local_count --- include/usermanager.h | 2 ++ src/inspircd.cpp | 2 -- src/usermanager.cpp | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/usermanager.h b/include/usermanager.h index 743db508a..ac8ae1cb3 100644 --- a/include/usermanager.h +++ b/include/usermanager.h @@ -32,6 +32,8 @@ class CoreExport UserManager */ clonemap local_clones; public: + UserManager(); + ~UserManager() { for (user_hash::iterator i = clientlist->begin();i != clientlist->end();i++) diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 344e2a473..4def50c87 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -375,8 +375,6 @@ InspIRCd::InspIRCd(int argc, char** argv) : // Create base manager classes early, so nothing breaks this->Users = new UserManager; - this->Users->unregistered_count = 0; - this->Users->clientlist = new user_hash(); this->Users->uuidlist = new user_hash(); this->chanlist = new chan_hash(); diff --git a/src/usermanager.cpp b/src/usermanager.cpp index 670add777..076277a33 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -24,6 +24,11 @@ #include "xline.h" #include "bancache.h" +UserManager::UserManager() + : unregistered_count(0), local_count(0) +{ +} + /* add a client connection to the sockets list */ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) { -- cgit v1.3.1-10-gc9f91