From edece3c71354464fcb000f9262feab725260d1c4 Mon Sep 17 00:00:00 2001 From: Subhransu Mohanty Date: Fri, 4 Dec 2020 18:08:25 +0900 Subject: [PATCH] use string_view to avoid string copy Change-Id: I44af920c24d7ffe8722272118c39163003f6b08e --- dali-toolkit/devel-api/builder/tree-node.cpp | 12 ++++++------ dali-toolkit/devel-api/builder/tree-node.h | 8 ++++---- dali-toolkit/internal/builder/tree-node-manipulator.cpp | 3 +-- dali-toolkit/internal/builder/tree-node-manipulator.h | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/dali-toolkit/devel-api/builder/tree-node.cpp b/dali-toolkit/devel-api/builder/tree-node.cpp index ef0071d..0d04753 100644 --- a/dali-toolkit/devel-api/builder/tree-node.cpp +++ b/dali-toolkit/devel-api/builder/tree-node.cpp @@ -103,7 +103,7 @@ size_t TreeNode::Size() const return c; } -size_t TreeNode::Count(const std::string& childName) const +size_t TreeNode::Count(std::string_view childName) const { const TreeNode* c = GetChild(childName); if(c) @@ -116,12 +116,12 @@ size_t TreeNode::Count(const std::string& childName) const } } -const TreeNode* TreeNode::GetChild(const std::string& childName) const +const TreeNode* TreeNode::GetChild(std::string_view childName) const { const TreeNode* p = mFirstChild; while(p) { - if(p->mName && (std::string(p->mName) == childName)) + if(p->mName && (std::string_view(p->mName) == childName)) { return p; } @@ -130,7 +130,7 @@ const TreeNode* TreeNode::GetChild(const std::string& childName) const return NULL; } -const TreeNode* TreeNode::GetChildIgnoreCase(const std::string& childName) const +const TreeNode* TreeNode::GetChildIgnoreCase(std::string_view childName) const { const TreeNode* p = mFirstChild; while(p) @@ -144,9 +144,9 @@ const TreeNode* TreeNode::GetChildIgnoreCase(const std::string& childName) const return NULL; } -const TreeNode* TreeNode::Find(const std::string& childName) const +const TreeNode* TreeNode::Find(std::string_view childName) const { - if(mName && std::string(mName) == childName) + if(mName && std::string_view(mName) == childName) { return this; } diff --git a/dali-toolkit/devel-api/builder/tree-node.h b/dali-toolkit/devel-api/builder/tree-node.h index e7e511e..6246b16 100644 --- a/dali-toolkit/devel-api/builder/tree-node.h +++ b/dali-toolkit/devel-api/builder/tree-node.h @@ -130,7 +130,7 @@ public: * @param childName The name of the child to find * @return the number of children in the found child */ - size_t Count(const std::string& childName) const; + size_t Count(std::string_view childName) const; /* * Get the nodes name @@ -184,21 +184,21 @@ public: * @param name The name of the child. * @return The child if found, else NULL */ - const TreeNode* GetChild(const std::string& name) const; + const TreeNode* GetChild(std::string_view name) const; /* * Gets a child of the node (using case insensitive matching) * @param name The name of the child in lower case * @return The child if found, else NULL */ - const TreeNode* GetChildIgnoreCase(const std::string& name) const; + const TreeNode* GetChildIgnoreCase(std::string_view name) const; /* * Recursively search for a child of the node * @param name The name of the child * @return The child if found, else NULL */ - const TreeNode* Find(const std::string& name) const; + const TreeNode* Find(std::string_view name) const; private: friend class Internal::TreeNodeManipulator; diff --git a/dali-toolkit/internal/builder/tree-node-manipulator.cpp b/dali-toolkit/internal/builder/tree-node-manipulator.cpp index 9567306..06ba033 100644 --- a/dali-toolkit/internal/builder/tree-node-manipulator.cpp +++ b/dali-toolkit/internal/builder/tree-node-manipulator.cpp @@ -549,8 +549,7 @@ void TreeNodeManipulator::DoWrite(const TreeNode *value, std::ostream& output, i } // switch } // DoWrite - -const TreeNode* FindIt(const std::string& childName, const TreeNode* node) +const TreeNode* FindIt(std::string_view childName, const TreeNode* node) { DALI_ASSERT_DEBUG(node); diff --git a/dali-toolkit/internal/builder/tree-node-manipulator.h b/dali-toolkit/internal/builder/tree-node-manipulator.h index eaea13e..cc9e98b 100644 --- a/dali-toolkit/internal/builder/tree-node-manipulator.h +++ b/dali-toolkit/internal/builder/tree-node-manipulator.h @@ -241,7 +241,7 @@ void DepthFirst( TreeNode* node, Operation& operation) * @param tree The tree to search * @return the TreeNode if found, else NULL */ -const TreeNode* FindIt(const std::string& childName, const TreeNode* tree); +const TreeNode* FindIt(std::string_view childName, const TreeNode* tree); /* * Copy string to a buffer -- 2.7.4