use string_view to avoid temporary string allocation. 24/242424/5
authorSubhransu Mohanty <sub.mohanty@samsung.com>
Thu, 27 Aug 2020 00:38:27 +0000 (09:38 +0900)
committerSubhransu Mohanty <sub.mohanty@samsung.com>
Fri, 11 Sep 2020 02:22:38 +0000 (11:22 +0900)
Change-Id: I234742fc0ad1337e54b56fcb916f435d487da2c5

dali-toolkit/devel-api/builder/tree-node.cpp
dali-toolkit/internal/builder/dictionary.h

index 0825905..ef0071d 100644 (file)
@@ -18,8 +18,8 @@
 // EXTERNAL INCLUDES
 #include <algorithm>
 #include <cctype>
-#include <cstring>
 #include <string>
+#include <string_view>
 
 // INTERNAL INCLUDES
 #include "dali-toolkit/devel-api/builder/tree-node.h"
 
 namespace Dali
 {
-bool CaseInsensitiveCharacterCompare(unsigned char a, unsigned char b)
-{
-  // Converts to lower case in the current locale.
-  return std::tolower(a) == std::tolower(b);
-}
 
 /**
  * return true if the lower cased ASCII strings are equal.
  */
-bool CaseInsensitiveStringCompare(const std::string& a, const std::string& b)
+bool CaseInsensitiveStringCompare(std::string_view a, std::string_view b)
 {
-  bool result = false;
-  if(a.length() == b.length())
-  {
-    result = std::equal(a.begin(), a.end(), b.begin(), CaseInsensitiveCharacterCompare);
-  }
-  return result;
+  return (a.length() == b.length()) && std::equal(a.begin(), a.end(), b.begin(), [](auto x, auto y) {
+           return std::tolower(x) == std::tolower(y);
+         });
 }
 
 namespace Toolkit
@@ -143,13 +135,9 @@ const TreeNode* TreeNode::GetChildIgnoreCase(const std::string& childName) const
   const TreeNode* p = mFirstChild;
   while(p)
   {
-    if(p->mName)
+    if(p->mName && CaseInsensitiveStringCompare(p->mName, childName))
     {
-      std::string nodeName(p->mName);
-      if(CaseInsensitiveStringCompare(nodeName, childName))
-      {
-        return p;
-      }
+      return p;
     }
     p = p->mNextSibling;
   }
index 88095eb..65c7e18 100644 (file)
  */
 
 #include <dali/public-api/common/vector-wrapper.h>
+
 #include <algorithm>
+#include <string_view>
 
 namespace Dali
 {
-extern bool CaseInsensitiveStringCompare( const std::string& a, const std::string& b );
+extern bool CaseInsensitiveStringCompare(std::string_view a, std::string_view b);
 
 namespace Toolkit
 {