From d03cd7be0622c75ed0f6b7c455b6356a53b9f0a2 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 20 Jan 2018 14:01:35 +0200 Subject: [PATCH] Speed optmization for method VContainer::ClearVariables(). --HG-- branch : develop --- src/app/valentina/xml/vpattern.cpp | 14 +++---- src/libs/vpatterndb/variables/vincrement_p.h | 12 +++--- src/libs/vpatterndb/vcontainer.cpp | 40 +++++++++++--------- src/libs/vpatterndb/vcontainer.h | 1 + 4 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 9b7742e47..d8ed9bc10 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -4148,13 +4148,13 @@ void VPattern::PrepareForParse(const Document &parse) { VContainer::ClearUniqueNames(); Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 8, "Check that you used all types"); - data->ClearVariables(VarType::Increment); - data->ClearVariables(VarType::LineAngle); - data->ClearVariables(VarType::LineLength); - data->ClearVariables(VarType::CurveLength); - data->ClearVariables(VarType::CurveCLength); - data->ClearVariables(VarType::ArcRadius); - data->ClearVariables(VarType::CurveAngle); + data->ClearVariables(QVector({VarType::Increment, + VarType::LineAngle, + VarType::LineLength, + VarType::CurveLength, + VarType::CurveCLength, + VarType::ArcRadius, + VarType::CurveAngle})); } } diff --git a/src/libs/vpatterndb/variables/vincrement_p.h b/src/libs/vpatterndb/variables/vincrement_p.h index 441a76460..b9e04dedd 100644 --- a/src/libs/vpatterndb/variables/vincrement_p.h +++ b/src/libs/vpatterndb/variables/vincrement_p.h @@ -61,12 +61,12 @@ public: // When we create an increment in the dialog it will get neccesary data. Such data must be removed because will // confuse a user. Increment should not know nothing about internal variables. Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 8, "Check that you used all types"); - this->data.ClearVariables(VarType::LineAngle); - this->data.ClearVariables(VarType::LineLength); - this->data.ClearVariables(VarType::CurveLength); - this->data.ClearVariables(VarType::CurveCLength); - this->data.ClearVariables(VarType::ArcRadius); - this->data.ClearVariables(VarType::CurveAngle); + this->data.ClearVariables(QVector({VarType::LineAngle, + VarType::LineLength, + VarType::CurveLength, + VarType::CurveCLength, + VarType::ArcRadius, + VarType::CurveAngle})); } VIncrementData(const VIncrementData &incr) diff --git a/src/libs/vpatterndb/vcontainer.cpp b/src/libs/vpatterndb/vcontainer.cpp index 672a2cac1..1ee71abfd 100644 --- a/src/libs/vpatterndb/vcontainer.cpp +++ b/src/libs/vpatterndb/vcontainer.cpp @@ -281,13 +281,13 @@ void VContainer::ClearForFullParse() d->pieces->clear(); d->piecePaths->clear(); Q_STATIC_ASSERT_X(static_cast(VarType::Unknown) == 8, "Check that you used all types"); - ClearVariables(VarType::Increment); - ClearVariables(VarType::LineAngle); - ClearVariables(VarType::LineLength); - ClearVariables(VarType::CurveLength); - ClearVariables(VarType::CurveCLength); - ClearVariables(VarType::ArcRadius); - ClearVariables(VarType::CurveAngle); + ClearVariables(QVector({VarType::Increment, + VarType::LineAngle, + VarType::LineLength, + VarType::CurveLength, + VarType::CurveCLength, + VarType::ArcRadius, + VarType::CurveAngle})); ClearGObjects(); ClearUniqueNames(); } @@ -311,27 +311,31 @@ void VContainer::ClearCalculationGObjects() //--------------------------------------------------------------------------------------------------------------------- void VContainer::ClearVariables(const VarType &type) { - if (d->variables.size()>0) //-V807 + ClearVariables(QVector({type})); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VContainer::ClearVariables(const QVector &types) +{ + if (not d->variables.isEmpty()) //-V807 { - if (type == VarType::Unknown) + if (types.isEmpty() || types.contains(VarType::Unknown)) { d->variables.clear(); } else { - QVector keys; QHash >::iterator i; - for (i = d->variables.begin(); i != d->variables.end(); ++i) + for (i = d->variables.begin(); i != d->variables.end();) { - if (i.value()->GetType() == type) + if (types.contains(i.value()->GetType())) { - keys.append(i.key()); + i = d->variables.erase(i); + } + else + { + ++i; } - } - - for (int i = 0; i < keys.size(); ++i) - { - d->variables.remove(keys.at(i)); } } } diff --git a/src/libs/vpatterndb/vcontainer.h b/src/libs/vpatterndb/vcontainer.h index 65999883d..a64556faf 100644 --- a/src/libs/vpatterndb/vcontainer.h +++ b/src/libs/vpatterndb/vcontainer.h @@ -172,6 +172,7 @@ public: void ClearGObjects(); void ClearCalculationGObjects(); void ClearVariables(const VarType &type = VarType::Unknown); + void ClearVariables(const QVector &types); static void ClearUniqueNames(); static void ClearUniqueIncrementNames();