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:
parent
f278fa10f0
commit
ac2647b212
1 changed files with 4 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue