From 3c56a2350eced54ddbbe1834467dd778afd275d9 Mon Sep 17 00:00:00 2001 From: jfa Date: Sat, 16 Dec 2023 00:55:20 +0000 Subject: [PATCH] [bos #39269] SHAPER is too slow compared to GEOM. Avoid using slow method Model_Document::index(), where possible. --- src/PartSet/PartSet_TreeNodes.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/PartSet/PartSet_TreeNodes.cpp b/src/PartSet/PartSet_TreeNodes.cpp index fc70a9f11..68fe1866a 100644 --- a/src/PartSet/PartSet_TreeNodes.cpp +++ b/src/PartSet/PartSet_TreeNodes.cpp @@ -538,13 +538,20 @@ void PartSet_FolderNode::update() if (!aDoc.get()) return; + std::string aGroup = groupName(); + // Remove extra sub-nodes - int aIndex; int aId = 0; + int nbObjs = aDoc->size(aGroup, true); while (aId < myChildren.size()) { ModuleBase_ITreeNode* aNode = myChildren.at(aId); - aIndex = aDoc->index(aNode->object(), true); - if ((aIndex == -1) || (aId != aIndex)) { + bool isObj = false; + if (aId < nbObjs) { + ObjectPtr aObj = aDoc->object(aGroup, aId, true); + if (aNode->object() == aObj) + isObj = true; + } + if (!isObj) { myChildren.removeAll(aNode); delete aNode; } else @@ -552,7 +559,6 @@ void PartSet_FolderNode::update() } // Add new nodes - std::string aGroup = groupName(); int aSize = aDoc->size(aGroup, true); for (int i = 0; i < aSize; i++) { ObjectPtr aObj = aDoc->object(aGroup, i, true); @@ -810,14 +816,21 @@ void PartSet_RootNode::update() DocumentPtr aDoc = document(); int aNb = numberOfFolders(); + std::string aGroup = ModelAPI_Feature::group(); + // Remove extra sub-nodes - int aIndex; int aId = 0; + int nbObjs = aDoc->size(aGroup, true); while (aId < myChildren.size()) { ModuleBase_ITreeNode* aNode = myChildren.at(aId); if (aNode->object().get()) { - aIndex = aDoc->index(aNode->object(), true); - if ((aIndex == -1) || (aId != (aIndex + aNb))) { + bool isObj = false; + if (aId - aNb < nbObjs) { + ObjectPtr aObj = aDoc->object(aGroup, aId - aNb, true); + if (aNode->object() == aObj) + isObj = true; + } + if (!isObj) { myChildren.removeAll(aNode); delete aNode; continue; @@ -827,7 +840,6 @@ void PartSet_RootNode::update() } // Add new nodes - std::string aGroup = ModelAPI_Feature::group(); int aSize = aDoc->size(aGroup, true); FeaturePtr aFeature; for (int i = 0; i < aSize; i++) { -- 2.39.2