From f66d05dbda78c44b9af40e3e6f4e1a50f802d054 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Thu, 20 Feb 2014 13:20:21 +0100 Subject: Create a name -> ModeHandler* map --- include/mode.h | 8 ++++++++ src/mode.cpp | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/include/mode.h b/include/mode.h index 2e40badca..4b8aa0935 100644 --- a/include/mode.h +++ b/include/mode.h @@ -479,6 +479,10 @@ class CoreExport ModeParser */ static const unsigned int MODETYPE_LAST = 2; + /** Type of the container that maps mode names to ModeHandlers + */ + typedef TR1NS::unordered_map ModeHandlerMap; + /** Mode handlers for each mode, to access a handler subtract * 65 from the ascii value of the mode letter. * The upper bit of the value indicates if its a usermode @@ -486,6 +490,10 @@ class CoreExport ModeParser */ ModeHandler* modehandlers[MODETYPE_LAST][128]; + /** A map of mode handlers keyed by their name + */ + ModeHandlerMap modehandlersbyname[MODETYPE_LAST]; + /** Lists of mode handlers by type */ struct diff --git a/src/mode.cpp b/src/mode.cpp index a2a0790b8..e70df5479 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -635,6 +635,9 @@ bool ModeParser::AddMode(ModeHandler* mh) if (slot) return false; + if (!modehandlersbyname[mh->GetModeType()].insert(std::make_pair(mh->name, mh)).second) + return false; + // Everything is fine, add the mode slot = mh; if (pm) @@ -651,6 +654,11 @@ bool ModeParser::DelMode(ModeHandler* mh) if ((mh->GetModeChar() < 'A') || (mh->GetModeChar() > 'z')) return false; + ModeHandlerMap& mhmap = modehandlersbyname[mh->GetModeType()]; + ModeHandlerMap::iterator mhmapit = mhmap.find(mh->name); + if ((mhmapit == mhmap.end()) || (mhmapit->second != mh)) + return false; + ModeHandler*& slot = modehandlers[mh->GetModeType()][mh->GetModeChar()-65]; if (slot != mh) return false; @@ -689,6 +697,7 @@ bool ModeParser::DelMode(ModeHandler* mh) break; } + mhmap.erase(mhmapit); slot = NULL; if (mh->IsPrefixMode()) mhlist.prefix.erase(std::find(mhlist.prefix.begin(), mhlist.prefix.end(), mh->IsPrefixMode())); -- cgit v1.2.3