]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/hashcomp.cpp
Merge pull request #1018 from SaberUK/insp20+hidekills
[user/henk/code/inspircd.git] / src / hashcomp.cpp
index 8c34c8a5603984f9f1a5cc5731beb73200ec5d17..e0347421b29d01fb89e7cedd13d89aacde04fb74 100644 (file)
@@ -127,15 +127,12 @@ void nspace::strlower(char *n)
        }
 }
 
-#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
-       size_t nspace::hash_compare<std::string, std::less<std::string> >::operator()(const std::string &s) const
+#ifdef HASHMAP_DEPRECATED
+       size_t CoreExport nspace::insensitive::operator()(const std::string &s) const
 #else
-       #ifdef HASHMAP_DEPRECATED
-               size_t CoreExport nspace::insensitive::operator()(const std::string &s) const
-       #else
-               size_t nspace::hash<std::string>::operator()(const std::string &s) const
-       #endif
+       size_t nspace::hash<std::string>::operator()(const std::string &s) const
 #endif
+
 {
        /* XXX: NO DATA COPIES! :)
         * The hash function here is practically
@@ -143,20 +140,16 @@ void nspace::strlower(char *n)
         * only with *x replaced with national_case_insensitive_map[*x].
         * This avoids a copy to use hash<const char*>
         */
-       register size_t t = 0;
+       size_t t = 0;
        for (std::string::const_iterator x = s.begin(); x != s.end(); ++x) /* ++x not x++, as its faster */
                t = 5 * t + national_case_insensitive_map[(unsigned char)*x];
        return t;
 }
 
 
-#if defined(WINDOWS) && !defined(HASHMAP_DEPRECATED)
-       size_t nspace::hash_compare<irc::string, std::less<irc::string> >::operator()(const irc::string &s) const
-#else
-       size_t CoreExport irc::hash::operator()(const irc::string &s) const
-#endif
+size_t CoreExport irc::hash::operator()(const irc::string &s) const
 {
-       register size_t t = 0;
+       size_t t = 0;
        for (irc::string::const_iterator x = s.begin(); x != s.end(); ++x) /* ++x not x++, as its faster */
                t = 5 * t + national_case_insensitive_map[(unsigned char)*x];
        return t;
@@ -333,7 +326,7 @@ bool irc::sepstream::GetToken(std::string &token)
                n++;
        }
 
-       token = "";
+       token.clear();
        return false;
 }
 
@@ -451,7 +444,7 @@ int irc::modestacker::GetStackedLine(std::vector<std::string> &result, int max_l
 irc::stringjoiner::stringjoiner(const std::string &seperator, const std::vector<std::string> &sequence, int begin, int end)
 {
        if (end < begin)
-               throw "stringjoiner logic error, this causes problems.";
+               return; // nothing to do here
 
        for (int v = begin; v < end; v++)
                joined.append(sequence[v]).append(seperator);
@@ -461,7 +454,7 @@ irc::stringjoiner::stringjoiner(const std::string &seperator, const std::vector<
 irc::stringjoiner::stringjoiner(const std::string &seperator, const std::deque<std::string> &sequence, int begin, int end)
 {
        if (end < begin)
-               throw "stringjoiner logic error, this causes problems.";
+               return; // nothing to do here
 
        for (int v = begin; v < end; v++)
                joined.append(sequence[v]).append(seperator);
@@ -471,7 +464,7 @@ irc::stringjoiner::stringjoiner(const std::string &seperator, const std::deque<s
 irc::stringjoiner::stringjoiner(const std::string &seperator, const char* const* sequence, int begin, int end)
 {
        if (end < begin)
-               throw "stringjoiner logic error, this causes problems.";
+               return; // nothing to do here
 
        for (int v = begin; v < end; v++)
                joined.append(sequence[v]).append(seperator);
@@ -483,29 +476,17 @@ std::string& irc::stringjoiner::GetJoined()
        return joined;
 }
 
-irc::portparser::portparser(const std::string &source, bool allow_overlapped) : in_range(0), range_begin(0), range_end(0), overlapped(allow_overlapped)
+irc::portparser::portparser(const std::string &source, bool allow_overlapped)
+       : sep(source), in_range(0), range_begin(0), range_end(0), overlapped(allow_overlapped)
 {
-       sep = new irc::commasepstream(source);
-       overlap_set.clear();
-}
-
-irc::portparser::~portparser()
-{
-       delete sep;
 }
 
 bool irc::portparser::Overlaps(long val)
 {
-       if (!overlapped)
+       if (overlapped)
                return false;
 
-       if (overlap_set.find(val) == overlap_set.end())
-       {
-               overlap_set[val] = true;
-               return false;
-       }
-       else
-               return true;
+       return (!overlap_set.insert(val).second);
 }
 
 long irc::portparser::GetToken()
@@ -533,14 +514,14 @@ long irc::portparser::GetToken()
        }
 
        std::string x;
-       sep->GetToken(x);
+       sep.GetToken(x);
 
        if (x.empty())
                return 0;
 
        while (Overlaps(atoi(x.c_str())))
        {
-               if (!sep->GetToken(x))
+               if (!sep.GetToken(x))
                        return 0;
        }