From 138fb540716d12bf1f89ec484d3210d921f9f3f7 Mon Sep 17 00:00:00 2001 From: brain Date: Sun, 31 Dec 2006 02:45:21 +0000 Subject: Make this new idea O(1) instead of O(x*y) git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6189 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_chghost.cpp | 13 ++++++++----- src/modules/m_sethost.cpp | 15 +++++++++------ 2 files changed, 17 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/modules/m_chghost.cpp b/src/modules/m_chghost.cpp index 3ce3d37bd..7d629187f 100644 --- a/src/modules/m_chghost.cpp +++ b/src/modules/m_chghost.cpp @@ -40,7 +40,7 @@ class cmd_chghost : public command_t for (; *x; x++) { - if (!strchr(hostmap, *x)) + if (!hostmap[*x]) { user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Invalid characters in hostname"); return CMD_FAILURE; @@ -71,11 +71,11 @@ class ModuleChgHost : public Module { cmd_chghost* mycommand; char* hostmap; - std::string hmap; public: ModuleChgHost(InspIRCd* Me) : Module::Module(Me) { + hostmap = new char[256]; OnRehash(""); mycommand = new cmd_chghost(ServerInstance, hostmap); ServerInstance->AddCommand(mycommand); @@ -89,16 +89,19 @@ class ModuleChgHost : public Module void OnRehash(const std::string ¶meter) { ConfigReader Conf(ServerInstance); - hmap = Conf.ReadValue("hostname", "charmap", 0); + std::string hmap = Conf.ReadValue("hostname", "charmap", 0); if (hmap.empty()) hostmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789"; - else - hostmap = (char*)hmap.c_str(); + + memset(&hostmap, 0, sizeof(hostmap)); + for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++) + hostmap[*n] = 1; } ~ModuleChgHost() { + delete[] hostmap; } Version GetVersion() diff --git a/src/modules/m_sethost.cpp b/src/modules/m_sethost.cpp index f05d2c8a4..0e116888c 100644 --- a/src/modules/m_sethost.cpp +++ b/src/modules/m_sethost.cpp @@ -39,7 +39,7 @@ class cmd_sethost : public command_t size_t len = 0; for (const char* x = parameters[0]; *x; x++, len++) { - if (!strchr(hostmap, *x)) + if (!hostmap[(unsigned char)*x]) { user->WriteServ("NOTICE "+std::string(user->nick)+" :*** Invalid characters in hostname"); return CMD_FAILURE; @@ -65,11 +65,11 @@ class ModuleSetHost : public Module { cmd_sethost* mycommand; char* hostmap; - std::string hmap; public: ModuleSetHost(InspIRCd* Me) : Module::Module(Me) { + hostmap = new char[256]; OnRehash(""); mycommand = new cmd_sethost(ServerInstance, hostmap); ServerInstance->AddCommand(mycommand); @@ -83,16 +83,19 @@ class ModuleSetHost : public Module void OnRehash(const std::string ¶meter) { ConfigReader Conf(ServerInstance); - hmap = Conf.ReadValue("hostname", "charmap", 0); + std::string hmap = Conf.ReadValue("hostname", "charmap", 0); if (hmap.empty()) - hostmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789"; - else - hostmap = (char*)hmap.c_str(); + hmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-_/0123456789"; + + memset(&hostmap, 0, sizeof(hostmap)); + for (std::string::iterator n = hmap.begin(); n != hmap.end(); n++) + hostmap[(unsigned char)*n] = 1; } virtual ~ModuleSetHost() { + delete[] hostmap; } virtual Version GetVersion() -- cgit v1.2.3