Skip to content

Commit

Permalink
feat(dom): perf code && adjust needSortByIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
zealotchen0 committed Apr 12, 2024
1 parent 15e2f88 commit 541e9da
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion dom/src/dom/root_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ void RootNode::CreateDomNodes(std::vector<std::shared_ptr<DomInfo>>&& nodes, boo
// https://doc.weixin.qq.com/doc/w3_ANsAsgZ1ACckOPazHXERJqKHOCbP1?scode=AJEAIQdfAAogJJ2RicAMgAvQZ1ACc
// 排序要保证两个原则:1. 父节点在子节点前;2. 同一父节点的子节点,必须按照 index 从小到大的顺序排序
// 同一层级,不同父节点的子节点,位置可以交叉,但要保证原则2,即同一父节点子节点 index 是从小到大的顺序
std::stable_sort(nodes_to_create.begin(), nodes_to_create.end(), [](const std::shared_ptr<hippy::DomNode>& a, const std::shared_ptr<hippy::DomNode>& b)
std::stable_sort(
nodes_to_create.begin(),
nodes_to_create.end(),
[](const std::shared_ptr<hippy::DomNode>& a, const std::shared_ptr<hippy::DomNode>& b)
{
auto render_info_a = a->GetRenderInfo();
auto render_info_b = b->GetRenderInfo();
Expand Down
2 changes: 1 addition & 1 deletion driver/js/src/modules/scene_builder_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ std::shared_ptr<ClassTemplate<SceneBuilder>> RegisterSceneBuilder(const std::wea
auto nodes = HandleJsValue(scope->GetContext(), arguments[0], scope);
bool needSortByIndex = false;
if (argument_count == 2) {
needSortByIndex = scope->GetContext()->GetValueBoolean(arguments[1], &needSortByIndex);
scope->GetContext()->GetValueBoolean(arguments[1], &needSortByIndex);
}
SceneBuilder::Create(scope->GetDomManager(), scope->GetRootNode(), std::move(std::get<2>(nodes)), needSortByIndex);
return nullptr;
Expand Down

0 comments on commit 541e9da

Please sign in to comment.