From f8871c5bd2131b9fb9ee54575767b8262394ac06 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 1 Jul 2013 12:17:24 +0300 Subject: improve size() usage in stringutils. --- src/utils/stringutils.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/utils/stringutils.cpp') diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 69474bd93..da3f8dd06 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -338,10 +338,12 @@ std::string& replaceAll(std::string& context, const std::string& from, return context; size_t lookHere = 0; size_t foundHere; + const size_t fromSize = from.size(); + const size_t toSize = to.size(); while ((foundHere = context.find(from, lookHere)) != std::string::npos) { - context.replace(foundHere, from.size(), to); - lookHere = foundHere + to.size(); + context.replace(foundHere, fromSize, to); + lookHere = foundHere + toSize; } return context; } @@ -545,8 +547,9 @@ std::string packList(const std::list &list) str.append(*i).append("|"); ++ i; } - if (str.size() > 1) - str = str.substr(0, str.size() - 1); + const size_t sz = str.size(); + if (sz > 1) + str = str.substr(0, sz - 1); return str; } @@ -641,9 +644,10 @@ std::string &removeProtocol(std::string &url) bool strStartWith(const std::string &str1, const std::string &str2) { - if (str1.size() < str2.size()) + const size_t sz2 = str2.size(); + if (str1.size() < sz2) return false; - return str1.substr(0, str2.size()) == str2; + return str1.substr(0, sz2) == str2; } std::string getDateString() -- cgit v1.2.3-60-g2f50