From: mpv Date: Mon, 16 Jul 2018 10:27:59 +0000 (+0300) Subject: Some optimizations for the issue #2569 X-Git-Tag: SHAPER_V9_1_0RC1~73^2~50 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=64d85463102705c61c86364cc05b8df2d251bed1;p=modules%2Fshaper.git Some optimizations for the issue #2569 --- diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index ea15cc5df..a15df8a33 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -487,7 +487,7 @@ void Model_Objects::createHistory(const std::string& theGroupID) } else { // it may be a folder - ObjectPtr aFolder = folder(aRefs->Value(a)); + const ObjectPtr& aFolder = folder(aRefs->Value(a)); if (aFolder.get()) { // store folder information for the Features group only if (isFeature || isFolder) { @@ -535,11 +535,12 @@ void Model_Objects::updateHistory(const std::string theGroup) } } -ObjectPtr Model_Objects::folder(TDF_Label theLabel) const +const ObjectPtr& Model_Objects::folder(TDF_Label theLabel) const { if (myFolders.IsBound(theLabel)) return myFolders.Find(theLabel); - return ObjectPtr(); + static ObjectPtr anEmptyResult; + return anEmptyResult; } FeaturePtr Model_Objects::feature(TDF_Label theLabel) const @@ -1483,8 +1484,9 @@ std::shared_ptr Model_Objects::findFolder( continue; } - aFoundFolder = std::dynamic_pointer_cast(folder(aCurLabel)); - if (aFoundFolder) { + const ObjectPtr& aFolderObj = folder(aCurLabel); + if (aFolderObj.get()) { + aFoundFolder = std::dynamic_pointer_cast(aFolderObj); AttributeReferencePtr aLastFeatAttr = aFoundFolder->reference(ModelAPI_Folder::LAST_FEATURE_ID()); if (aLastFeatAttr) { @@ -1740,7 +1742,7 @@ FolderPtr Model_Objects::findContainingFolder(const FeaturePtr& theFeature, int& if (aFoundFolder) { if (isSkippedFeature(theFeature)) { theIndexInFolder = -1; - return false; + return FolderPtr(); } // decrease the index of the feature in the folder by the number of skipped features for (int anIndex = theIndexInFolder - 1; anIndex > 0; anIndex--) { @@ -1754,8 +1756,9 @@ FolderPtr Model_Objects::findContainingFolder(const FeaturePtr& theFeature, int& if (!aFoundFolder) { // if the current label refers to a folder, feel all necessary data - aFoundFolder = std::dynamic_pointer_cast(folder(aCurLabel)); - if (aFoundFolder) { + const ObjectPtr& aFolderObj = folder(aCurLabel); + if (aFolderObj.get()) { + aFoundFolder = std::dynamic_pointer_cast(aFolderObj); theIndexInFolder = -1; AttributeReferencePtr aLastRef = diff --git a/src/Model/Model_Objects.h b/src/Model/Model_Objects.h index 856d3c90b..d6f3d383f 100644 --- a/src/Model/Model_Objects.h +++ b/src/Model/Model_Objects.h @@ -292,7 +292,7 @@ class Model_Objects std::string& theParentName) const; /// Return object representing a folder or empty pointer - ObjectPtr folder(TDF_Label theLabel) const; + const ObjectPtr& folder(TDF_Label theLabel) const; private: TDF_Label myMain; ///< main label of the data storage diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 6c2f216e3..358e2403e 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -590,11 +590,12 @@ ObjectPtr XGUI_Displayer::getObject(const AISObjectPtr& theIO) const ObjectPtr XGUI_Displayer::getObject(const Handle(AIS_InteractiveObject)& theIO) const { ObjectPtr anObject; - foreach (ObjectPtr anObj, myResult2AISObjectMap.keys()) { - AISObjectPtr aAIS = myResult2AISObjectMap[anObj]; + ResultToAISMap::const_iterator aMapIter = myResult2AISObjectMap.cbegin(); + for (; aMapIter != myResult2AISObjectMap.cend(); aMapIter++) { + const AISObjectPtr& aAIS = aMapIter.value(); Handle(AIS_InteractiveObject) anAIS = aAIS->impl(); if (anAIS == theIO) - anObject = anObj; + anObject = aMapIter.key(); if (anObject.get()) break; }