mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-02 00:42:24 +00:00
COMMON: Performance improvement for toUppercase and toLowercase: Avoid calling makeUnique on strings that aren't modified.
This commit is contained in:
parent
a7b0254895
commit
e5e9d5c96d
@ -720,21 +720,37 @@ TEMPLATE void BASESTRING::wordWrap(const uint32 maxLength) {
|
||||
#endif
|
||||
|
||||
TEMPLATE void BASESTRING::toLowercase() {
|
||||
makeUnique();
|
||||
for (uint32 i = 0; i < _size; ++i) {
|
||||
if (_str[i] > 0 && _str[i] < 128) {
|
||||
_str[i] = tolower(_str[i]);
|
||||
}
|
||||
}
|
||||
toCase(tolower);
|
||||
}
|
||||
|
||||
TEMPLATE void BASESTRING::toUppercase() {
|
||||
makeUnique();
|
||||
for (uint32 i = 0; i < _size; ++i) {
|
||||
if (_str[i] > 0 && _str[i] < 128) {
|
||||
_str[i] = toupper(_str[i]);
|
||||
toCase(toupper);
|
||||
}
|
||||
|
||||
TEMPLATE void BASESTRING::toCase(int (*caseChangeFunc)(int)) {
|
||||
uint32 sz = _size;
|
||||
T *buf = _str;
|
||||
|
||||
uint32 i = 0;
|
||||
for ( ; i < sz; ++i) {
|
||||
value_type ch = buf[i];
|
||||
if (ch > 0 && ch < 128) {
|
||||
value_type newCh = static_cast<value_type>(caseChangeFunc(buf[i]));
|
||||
if (ch != newCh) {
|
||||
makeUnique();
|
||||
buf = _str;
|
||||
buf[i] = newCh;
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (; i < sz; ++i) {
|
||||
value_type ch = buf[i];
|
||||
if (ch > 0 && ch < 128)
|
||||
buf[i] = static_cast<value_type>(caseChangeFunc(ch));
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef SCUMMVM_UTIL
|
||||
|
@ -263,6 +263,8 @@ protected:
|
||||
|
||||
uint getUnsignedValue(uint pos) const;
|
||||
|
||||
void toCase(int (*caseChangeFunc)(int));
|
||||
|
||||
static uint32 cStrLen(const value_type *str);
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user