From 46018cde08a63132b3bbd406f8d80215b6dbb87d Mon Sep 17 00:00:00 2001 From: w00t Date: Tue, 24 Jul 2007 14:30:15 +0000 Subject: Refactor some craq to not loop through a string 4-5 times for a simple operation git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7539 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules.cpp | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'src/modules.cpp') diff --git a/src/modules.cpp b/src/modules.cpp index 9deaa7954..00d7e7871 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -509,27 +509,30 @@ bool InspIRCd::DelELine(const std::string &hostmask) bool InspIRCd::IsValidMask(const std::string &mask) { char* dest = (char*)mask.c_str(); - if (strchr(dest,'!')==0) - return false; - if (strchr(dest,'@')==0) - return false; - for (char* i = dest; *i; i++) - if (*i < 32) - return false; + int exclamation = 0; + int atsign = 0; + for (char* i = dest; *i; i++) - if (*i > 126) + { + /* out of range character, bad mask */ + if (*i < 32 || *i > 126) + { return false; - unsigned int c = 0; - for (char* i = dest; *i; i++) - if (*i == '!') - c++; - if (c>1) - return false; - c = 0; - for (char* i = dest; *i; i++) - if (*i == '@') - c++; - if (c>1) + } + + switch (*i) + { + case '!': + exclamation++; + break; + case '@': + atsign++; + break; + } + } + + /* valid masks only have 1 ! and @ */ + if (exclamation != 1 || atsign != 1) return false; return true; -- cgit v1.3.1-10-gc9f91