diff --git a/dom/include/dom/dom_node.h b/dom/include/dom/dom_node.h index e56964c9deb..8b957411a44 100644 --- a/dom/include/dom/dom_node.h +++ b/dom/include/dom/dom_node.h @@ -119,6 +119,8 @@ class DomNode : public std::enable_shared_from_this { inline void SetLayoutOnly(bool layout_only) { layout_only_ = layout_only; } inline bool IsVirtual() { return is_virtual_; } inline void SetIsVirtual(bool is_virtual) { is_virtual_ = is_virtual; } + inline bool IsEnableEliminated() { return enable_eliminated_; } + inline void SetEnableEliminated(bool enable_eliminated) { enable_eliminated_ = enable_eliminated; } inline void SetIndex(int32_t index) { index_ = index; } inline int32_t GetIndex() const { return index_; } inline void SetRootNode(std::weak_ptr root_node) { root_node_ = root_node; } @@ -230,6 +232,10 @@ class DomNode : public std::enable_shared_from_this { bool is_virtual_{}; bool layout_only_ = false; + // Node can only be eliminated for the first time, + // and if they cannot be eliminated for the first time, they cannot be eliminated at all times. + bool enable_eliminated_ = true; + std::weak_ptr parent_; std::vector> children_; diff --git a/dom/include/dom/layer_optimized_render_manager.h b/dom/include/dom/layer_optimized_render_manager.h index a060bad94df..73c76d3d2ba 100644 --- a/dom/include/dom/layer_optimized_render_manager.h +++ b/dom/include/dom/layer_optimized_render_manager.h @@ -73,10 +73,6 @@ class LayerOptimizedRenderManager : public RenderManager { void FindValidChildren(const std::shared_ptr& node, std::vector>& valid_children_nodes); - - // Record nodes that cannot be eliminated. Nodes can only be eliminated for the first time, - // and if they cannot be eliminated for the first time, they cannot be eliminated at all times. - std::set not_eliminated_node_ids_; }; } // namespace dom diff --git a/dom/src/dom/layer_optimized_render_manager.cc b/dom/src/dom/layer_optimized_render_manager.cc index fa70cf2686f..646b8befcef 100644 --- a/dom/src/dom/layer_optimized_render_manager.cc +++ b/dom/src/dom/layer_optimized_render_manager.cc @@ -128,19 +128,6 @@ void LayerOptimizedRenderManager::DeleteRenderNode(std::weak_ptr root_ FOOTSTONE_DLOG(INFO) << "[Hippy Statistic] delete node size before optimize = " << nodes.size() << ", delete node size after optimize = " << nodes_to_delete.size(); if (!nodes_to_delete.empty()) { - for (auto& node : nodes_to_delete) { - // Recursively delete all ids on the node tree. - std::vector> node_stack; - node_stack.push_back(node); - while (!node_stack.empty()) { - auto back_node = node_stack.back(); - node_stack.pop_back(); - not_eliminated_node_ids_.erase(back_node->GetId()); - for (auto& child : back_node->GetChildren()) { - node_stack.push_back(child); - } - } - } render_manager_->DeleteRenderNode(root_node, std::move(nodes_to_delete)); } } @@ -289,10 +276,9 @@ bool LayerOptimizedRenderManager::IsJustLayoutProp(const char *prop_name) const } bool LayerOptimizedRenderManager::CanBeEliminated(const std::shared_ptr& node) { - bool eliminated = (node->IsLayoutOnly() || node->IsVirtual()) && - (not_eliminated_node_ids_.find(node->GetId()) == not_eliminated_node_ids_.end()); + bool eliminated = (node->IsLayoutOnly() || node->IsVirtual()) && node->IsEnableEliminated(); if (!eliminated) { - not_eliminated_node_ids_.insert(node->GetId()); + node->SetEnableEliminated(false); } return eliminated; }