From f5eff8196f8021a5a162e0ae23c09d2295334212 Mon Sep 17 00:00:00 2001 From: psychon Date: Tue, 6 Jan 2009 09:43:18 +0000 Subject: [PATCH] Make CString::Trim*() faster Before, they would remove one character at a time. Now they do everything at once. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1322 726aef4b-f618-498e-8847-2d620e286838 --- ZNCString.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/ZNCString.cpp b/ZNCString.cpp index 28eb397b..8a69c19a 100644 --- a/ZNCString.cpp +++ b/ZNCString.cpp @@ -937,25 +937,31 @@ bool CString::Trim(const CString& s) { } bool CString::TrimLeft(const CString& s) { - bool bRet = false; + size_type i = find_first_not_of(s); - while (length() && s.find(Left(1)) != CString::npos) { - LeftChomp(); - bRet = true; - } + if (i == 0) + return false; - return bRet; + if (i != npos) + this->erase(0, i); + else + this->clear(); + + return true; } bool CString::TrimRight(const CString& s) { - bool bRet = false; + size_type i = find_last_not_of(s); - while (length() && s.find(Right(1)) != CString::npos) { - RightChomp(); - bRet = true; - } + if (i + 1 == length()) + return false; - return bRet; + if (i != npos) + this->erase(i + 1, npos); + else + this->clear(); + + return true; } CString CString::Trim_n(const CString& s) const {