Avoid unnecessary vector resizing (tstring.toLower) (#614)

Directory listing compares full paths case insensitive,
this causes toLower to run a lot.

While this could be avoided entirely, at least avoid resizing the vector while lower casing strings.
This commit is contained in:
Campbell Barton 2016-07-13 21:52:24 +10:00 committed by Shinya Kitaoka
parent f278fa10f0
commit ac2647b212

View file

@ -157,10 +157,11 @@ std::wstring toLower(std::wstring a) {
#ifdef _WIN32
return _wcslwr(const_cast<wchar_t *>(a.c_str()));
#else
const int length = (int)a.length();
std::wstring ret;
for (int i = 0; i < (int)a.length(); i++) {
wchar_t c = towlower(a[i]);
ret += c;
ret.resize(length);
for (int i = 0; i < length; i++) {
ret[i] = towlower(a[i]);
}
return ret;
#endif