Reduce useless memory reallocation in String::upper().
authorTsuda Kageyu <tsuda.kageyu@gmail.com>
Fri, 27 Jan 2017 16:17:21 +0000 (01:17 +0900)
committerTsuda Kageyu <tsuda.kageyu@gmail.com>
Fri, 27 Jan 2017 16:17:21 +0000 (01:17 +0900)
taglib/ape/apetag.cpp
taglib/mpeg/id3v2/frames/unsynchronizedlyricsframe.cpp
taglib/mpeg/id3v2/frames/urllinkframe.cpp
taglib/toolkit/tstring.cpp

index 92ad536fdb4100aba758cfb2648c1896cf4ea080..79e1d5cc7c53f064d22d39fd7f871a1697d5304c 100644 (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;
     }
 
index 87317d322435a2003c063bc0e7b7d4ba3b01214a..eafae171ca90fc6de5f001ed41553a6602e4de44 100644 (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());
index 99e4fb7f7931912ba7f3dfe0e94974d085865084..543b5184d52148677b6010eb8b38dc33008bf9ae 100644 (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());
index bee4fb7eb59053f66cbb02d1092084cddd0283b3..863bbf59f38df7f4269b8b00c7d625786e952068 100644 (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);
   }