]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Some optimizations for the issue #2569
authormpv <mpv@opencascade.com>
Mon, 16 Jul 2018 10:27:59 +0000 (13:27 +0300)
committermpv <mpv@opencascade.com>
Mon, 16 Jul 2018 10:27:59 +0000 (13:27 +0300)
src/Model/Model_Objects.cpp
src/Model/Model_Objects.h
src/XGUI/XGUI_Displayer.cpp

index ea15cc5df381011502c27c81cd1a217e58dadaee..a15df8a33ca902e37470007704864c341c2c3182 100644 (file)
@@ -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<ModelAPI_Folder> Model_Objects::findFolder(
       continue;
     }
 
-    aFoundFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(folder(aCurLabel));
-    if (aFoundFolder) {
+    const ObjectPtr& aFolderObj = folder(aCurLabel);
+    if (aFolderObj.get()) {
+      aFoundFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(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<ModelAPI_Folder>(folder(aCurLabel));
-      if (aFoundFolder) {
+      const ObjectPtr& aFolderObj = folder(aCurLabel);
+      if (aFolderObj.get()) {
+        aFoundFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(aFolderObj);
         theIndexInFolder = -1;
 
         AttributeReferencePtr aLastRef =
index 856d3c90b12f87cb96a40e91ada6c4dec8ac0327..d6f3d383f741867d3258b2947d2011fa034f2052 100644 (file)
@@ -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
index 6c2f216e38dc4f4b9f61017dab69fbb0c9b61295..358e2403e7a1801a51614884882615286a2ed31a 100644 (file)
@@ -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<Handle(AIS_InteractiveObject)>();
     if (anAIS == theIO)
-      anObject = anObj;
+      anObject = aMapIter.key();
     if (anObject.get())
       break;
   }