From e81b07fcb5008cdb24cd290d46e1f96c3ac3ec29 Mon Sep 17 00:00:00 2001 From: caremoli Date: Tue, 29 Jun 2010 16:33:46 +0000 Subject: [PATCH] CCAR: optimisation of attributetarget for large number of refs --- .../SALOMEDSImpl_AttributeTarget.cxx | 25 ++++++------------- .../SALOMEDSImpl_AttributeTarget.hxx | 7 ++++-- 2 files changed, 13 insertions(+), 19 deletions(-) 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..a7b1cf2db 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTarget.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTarget.hxx @@ -33,13 +33,15 @@ #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::vector myVariables; + std::map< std::string , DF_Attribute* > myVariables; public: static const std::string& GetID() ; @@ -50,7 +52,8 @@ 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; } + //std::vector& GetVariables() { return myVariables; } const std::string& ID() const; void Restore(DF_Attribute* with) ; DF_Attribute* NewEmpty() const; -- 2.39.2