From 7da2c69fb520d2aaaf7c144f6ef84f56d33d7347 Mon Sep 17 00:00:00 2001 From: etkmao Date: Mon, 4 Sep 2023 15:27:59 +0800 Subject: [PATCH] fix(core): fix performance for dom node --- dom/src/dom/dom_node.cc | 6 +++--- dom/src/dom/root_node.cc | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dom/src/dom/dom_node.cc b/dom/src/dom/dom_node.cc index 97abf0bb850..777e4d48a91 100644 --- a/dom/src/dom/dom_node.cc +++ b/dom/src/dom/dom_node.cc @@ -103,13 +103,13 @@ std::shared_ptr DomNode::GetChildAt(size_t index) { } int32_t DomNode::AddChildByRefInfo(const std::shared_ptr& dom_info) { - std::shared_ptr ref_info = dom_info->ref_info; + std::shared_ptr& ref_info = dom_info->ref_info; if (ref_info) { if (children_.size() == 0) { children_.push_back(dom_info->dom_node); } else { for (uint32_t i = 0; i < children_.size(); ++i) { - auto child = children_[i]; + auto& child = children_[i]; if (ref_info->ref_id == child->GetId()) { if (ref_info->relative_to_ref == RelativeType::kFront) { children_.insert( @@ -145,7 +145,7 @@ int32_t DomNode::AddChildByRefInfo(const std::shared_ptr& dom_info) { int32_t DomNode::GetChildIndex(uint32_t id) { int32_t index = -1; for (uint32_t i = 0; i < children_.size(); ++i) { - auto child = children_[i]; + auto& child = children_[i]; if (child && child->GetId() == id) { index = static_cast(i); break; diff --git a/dom/src/dom/root_node.cc b/dom/src/dom/root_node.cc index 31059bcf9bf..4963c0f2bbf 100644 --- a/dom/src/dom/root_node.cc +++ b/dom/src/dom/root_node.cc @@ -74,7 +74,7 @@ void RootNode::CreateDomNodes(std::vector>&& nodes) { } std::vector> nodes_to_create; for (const auto& node_info : nodes) { - auto node = node_info->dom_node; + auto& node = node_info->dom_node; std::shared_ptr parent_node = GetNode(node->GetPid()); if (parent_node == nullptr) { continue;