From: caremoli Date: Tue, 28 Sep 2010 15:09:14 +0000 (+0000) Subject: CCAR: fix a performance problem when adding references in study (AttributeTarget) X-Git-Tag: V5_1_5a1~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8fa9a623faabd5540d86f6c0425f71d8ff152287;p=modules%2Fkernel.git CCAR: fix a performance problem when adding references in study (AttributeTarget) replace the vector by a map< std::string , DF_Attribute* > where the key is the label of the DF_Attribute* to improve access time to an attribute with given label (main performance bottleneck during explode) --- diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTarget.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTarget.cxx index 72eeda9c8..ae2c2414f 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTarget.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTarget.cxx @@ -86,8 +86,7 @@ void SALOMEDSImpl_AttributeTarget::Add(const SALOMEDSImpl_SObject& theSO) DF_Label aRefLabel = theSO.GetLabel(); SALOMEDSImpl_AttributeReference* aReference; if ((aReference=(SALOMEDSImpl_AttributeReference*)aRefLabel.FindAttribute(SALOMEDSImpl_AttributeReference::GetID()))) { - for(int i = 0, len = myVariables.size(); iLabel() == aRefLabel) return; //BugID: PAL6192 - myVariables.push_back(aReference); + myVariables[aRefLabel.Entry()]=aReference; } SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved @@ -101,8 +100,8 @@ std::vector SALOMEDSImpl_AttributeTarget::Get() { std::vector aSeq; - for(int i = 0, len = myVariables.size(); iLabel())); + for (std::map< std::string , DF_Attribute* >::iterator iter = myVariables.begin(); iter != myVariables.end(); ++iter) + aSeq.push_back( SALOMEDSImpl_Study::SObject(iter->second->Label())); return aSeq; } @@ -116,15 +115,7 @@ void SALOMEDSImpl_AttributeTarget::Remove(const SALOMEDSImpl_SObject& theSO) Backup(); DF_Label aRefLabel = theSO.GetLabel(); - std::vector va; - for(int i = 0, len = myVariables.size(); iLabel(); - if(myVariables[i]->Label() == aRefLabel) continue; - va.push_back(myVariables[i]); - } - - myVariables.clear(); - myVariables = va; + myVariables.erase(aRefLabel.Entry()); SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } @@ -144,8 +135,8 @@ void SALOMEDSImpl_AttributeTarget::Restore(DF_Attribute* With) SALOMEDSImpl_AttributeTarget* REL = dynamic_cast(With); myRelation = REL->GetRelation(); myVariables.clear(); - for (int i = 0, len = REL->myVariables.size(); imyVariables[i]); + for (std::map< std::string , DF_Attribute* >::iterator iter = REL->myVariables.begin(); iter != REL->myVariables.end(); ++iter){ + myVariables[iter->first]=iter->second; } } @@ -167,7 +158,7 @@ void SALOMEDSImpl_AttributeTarget::Paste(DF_Attribute* into) SALOMEDSImpl_AttributeTarget* REL = dynamic_cast(into); REL->SetRelation(myRelation); REL->myVariables.clear(); - for (int i = 0, len = myVariables.size(); imyVariables.push_back(myVariables[i]); + for (std::map< std::string , DF_Attribute* >::iterator iter = myVariables.begin(); iter != myVariables.end(); ++iter){ + REL->myVariables[iter->first]=iter->second; } } diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTarget.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTarget.hxx index f5a1849bf..842931bc4 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTarget.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTarget.hxx @@ -33,13 +33,14 @@ #include #include "SALOMEDSImpl_GenericAttribute.hxx" #include "SALOMEDSImpl_SObject.hxx" +#include class SALOMEDSIMPL_EXPORT SALOMEDSImpl_AttributeTarget : public SALOMEDSImpl_GenericAttribute { private: std::string myRelation; - std::vector myVariables; + std::map< std::string , DF_Attribute* > myVariables; public: static const std::string& GetID() ; @@ -50,7 +51,7 @@ public: void Remove(const SALOMEDSImpl_SObject& theSO); std::string GetRelation() { return myRelation; } void SetRelation(const std::string& theRelation); - std::vector& GetVariables() { return myVariables; } + std::map< std::string , DF_Attribute* >& GetVariables() { return myVariables; } const std::string& ID() const; void Restore(DF_Attribute* with) ; DF_Attribute* NewEmpty() const;