Skip to content
Snippets Groups Projects
Commit 29f0a780 authored by andreykproductengine's avatar andreykproductengine
Browse files

SL-10930 LLStringUtil pointlessly scan the string

parent 68307a81
No related branches found
No related tags found
No related merge requests found
...@@ -1735,7 +1735,8 @@ bool LLStringUtilBase<T>::startsWith( ...@@ -1735,7 +1735,8 @@ bool LLStringUtilBase<T>::startsWith(
const string_type& substr) const string_type& substr)
{ {
if(string.empty() || (substr.empty())) return false; if(string.empty() || (substr.empty())) return false;
if(0 == string.find(substr)) return true; if (substr.length() > string.length()) return false;
if (0 == string.compare(0, substr.length(), substr)) return true;
return false; return false;
} }
...@@ -1746,9 +1747,11 @@ bool LLStringUtilBase<T>::endsWith( ...@@ -1746,9 +1747,11 @@ bool LLStringUtilBase<T>::endsWith(
const string_type& substr) const string_type& substr)
{ {
if(string.empty() || (substr.empty())) return false; if(string.empty() || (substr.empty())) return false;
std::string::size_type idx = string.rfind(substr); size_t sub_len = substr.length();
if(std::string::npos == idx) return false; size_t str_len = string.length();
return (idx == (string.size() - substr.size())); if (sub_len > str_len) return false;
if (0 == string.compare(str_len - sub_len, sub_len, substr)) return true;
return false;
} }
// static // static
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment