Reduce useless memory reallocation in String::upper().

This commit is contained in:
Tsuda Kageyu
2017-01-28 01:17:21 +09:00
parent 3d14ff74b1
commit 922fd611ae
4 changed files with 6 additions and 6 deletions

View File

@ -62,8 +62,9 @@ namespace
return false;
}
const String upperKey = String(key).upper();
for(size_t i = 0; invalidKeys[i] != 0; ++i) {
if(String(key).upper() == invalidKeys[i])
if(upperKey == invalidKeys[i])
return false;
}

View File

@ -118,7 +118,7 @@ PropertyMap UnsynchronizedLyricsFrame::asProperties() const
{
PropertyMap map;
String key = description().upper();
if(key.isEmpty() || key.upper() == "LYRICS")
if(key.isEmpty() || key == "LYRICS")
map.insert("LYRICS", text());
else
map.insert("LYRICS:" + key, text());

View File

@ -170,7 +170,7 @@ PropertyMap UserUrlLinkFrame::asProperties() const
{
PropertyMap map;
String key = description().upper();
if(key.isEmpty() || key.upper() == "URL")
if(key.isEmpty() || key == "URL")
map.insert("URL", url());
else
map.insert("URL:" + key, url());

View File

@ -469,12 +469,11 @@ String & String::clear()
String String::upper() const
{
String s;
static int shift = 'A' - 'a';
s.d->data.reserve(size());
for(ConstIterator it = begin(); it != end(); ++it) {
if(*it >= 'a' && *it <= 'z')
s.d->data.push_back(*it + shift);
s.d->data.push_back(*it + 'A' - 'a');
else
s.d->data.push_back(*it);
}