From fa330fa9e04856353a372ea04903d5c3fcd5e20e Mon Sep 17 00:00:00 2001 From: jfa Date: Mon, 18 Dec 2023 13:22:13 +0000 Subject: [PATCH] [bos #39269] SHAPER is too slow compared to GEOM. Store object index. --- src/Model/Model_Objects.cpp | 31 +++++++++++++++++++++++++------ src/ModelAPI/ModelAPI_Object.cpp | 1 + src/ModelAPI/ModelAPI_Object.h | 13 +++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index 41b019b9b..ea1c271df 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -471,9 +471,12 @@ void Model_Objects::createHistory(const std::string& theGroupID) if (isFeature) { // here may be also disabled features if (!isSub && aFeature->isInHistory()) { aResult.push_back(aFeature); + aFeature->setHistoryIndex(aResult.size() - 1); // the feature is out of the folders - if (aLastFeatureInFolder.get() == NULL) + if (aLastFeatureInFolder.get() == NULL) { aResultOutOfFolder.push_back(aFeature); + aFeature->setHistoryIndex(aResultOutOfFolder.size() - 1, true); + } } } else if (!aFeature->isDisabled()) { // iterate all results of not-disabled feature // construction results of sub-features should not be in the tree @@ -487,6 +490,7 @@ void Model_Objects::createHistory(const std::string& theGroupID) if (aRes->groupName() != theGroupID) break; // feature have only same group results if (!aRes->isDisabled() && aRes->isInHistory() && !aRes->isConcealed()) { aResult.push_back(*aRIter); + (*aRIter)->setHistoryIndex(aResult.size() - 1); } } } @@ -503,8 +507,11 @@ void Model_Objects::createHistory(const std::string& theGroupID) // store folder information for the Features group only if (isFeature || isFolder) { aResult.push_back(aFolder); - if (!isFolder) + aFolder->setHistoryIndex(aResult.size() - 1); + if (!isFolder) { aResultOutOfFolder.push_back(aFolder); + aFolder->setHistoryIndex(aResultOutOfFolder.size() - 1, true); + } } // get the last feature in the folder @@ -669,12 +676,24 @@ const int Model_Objects::index(std::shared_ptr theObject, createHistory(aGroup); // get the group of features out of folder (if enabled) - if (theAllowFolder && !groupNameFoldering(aGroup, theAllowFolder).empty()) - aGroup = groupNameFoldering(aGroup, theAllowFolder); + bool isGroupNameFoldering = false; + const std::string& aGroupNameFoldering = groupNameFoldering(aGroup, theAllowFolder); + if (theAllowFolder && !aGroupNameFoldering.empty()) { + isGroupNameFoldering = true; + aGroup = aGroupNameFoldering; + } std::vector& allObjs = myHistory[aGroup]; - std::vector::iterator anObjIter = allObjs.begin(); // iterate to search object - for(int anIndex = 0; anObjIter != allObjs.end(); anObjIter++, anIndex++) { + + // try to use saved index (to aviod time consuming iteration) + int anIndex = theObject->getHistoryIndex(isGroupNameFoldering); + if (0 <= anIndex && anIndex < allObjs.size() && + allObjs[anIndex] == theObject) + return anIndex; + + // iterate to search object + std::vector::iterator anObjIter = allObjs.begin(); + for (anIndex = 0; anObjIter != allObjs.end(); anObjIter++, anIndex++) { if ((*anObjIter) == theObject) return anIndex; } diff --git a/src/ModelAPI/ModelAPI_Object.cpp b/src/ModelAPI/ModelAPI_Object.cpp index 371b72ff3..caef05ca1 100644 --- a/src/ModelAPI/ModelAPI_Object.cpp +++ b/src/ModelAPI/ModelAPI_Object.cpp @@ -62,6 +62,7 @@ void ModelAPI_Object::attributeChanged(const std::string& /*theID*/) } ModelAPI_Object::ModelAPI_Object() + : myHistoryIndex(-1) { } diff --git a/src/ModelAPI/ModelAPI_Object.h b/src/ModelAPI/ModelAPI_Object.h index 46c3f34f8..ae89592ce 100644 --- a/src/ModelAPI/ModelAPI_Object.h +++ b/src/ModelAPI/ModelAPI_Object.h @@ -45,6 +45,19 @@ class ModelAPI_Object: public ModelAPI_Entity { std::shared_ptr myData; ///< manager of the data model of a feature std::shared_ptr myDoc; ///< document this object belongs to + + int myHistoryIndex; ///< index in Model_Objects history, managed by Model_Objects + int myHistoryIndexOOF; ///< index in Model_Objects history, managed by Model_Objects + + /// set object's index in Model_Objects history, called by Model_Objects + void setHistoryIndex(int theIndex, bool isOutOfFolder = false) + { isOutOfFolder ? myHistoryIndexOOF = theIndex : myHistoryIndex = theIndex; } + + /// get object's index in Model_Objects history, called by Model_Objects + int getHistoryIndex(bool isOutOfFolder = false) + { if (isOutOfFolder) return myHistoryIndexOOF; + return myHistoryIndex; } + public: #ifdef DEBUG_NAMES std::wstring myName; // name of this object -- 2.39.2