From 7f84a0934229474e5f5e5c483a9dc0b73c10886c Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 20 Jan 2018 12:31:12 +0200 Subject: [PATCH] Optimization. Avoid expensive exception calls. --HG-- branch : develop --- src/app/valentina/xml/vpattern.cpp | 12 +----------- src/libs/ifc/xml/vabstractpattern.cpp | 9 +++------ src/libs/ifc/xml/vdomdocument.cpp | 13 +++---------- src/libs/vformat/vmeasurements.cpp | 22 ++-------------------- 4 files changed, 9 insertions(+), 47 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 76bf4158c..9b7742e47 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -3679,17 +3679,7 @@ void VPattern::ParseIncrementsElement(const QDomNode &node) if (domElement.tagName() == TagIncrement) { const QString name = GetParametrString(domElement, AttrName, ""); - - QString desc; - try - { - desc = GetParametrString(domElement, AttrDescription); - } - catch (VExceptionEmptyParameter &e) - { - Q_UNUSED(e) - } - + const QString desc = GetParametrEmptyString(domElement, AttrDescription); const QString formula = GetParametrString(domElement, AttrFormula, "0"); bool ok = false; const qreal value = EvalFormula(data, formula, &ok); diff --git a/src/libs/ifc/xml/vabstractpattern.cpp b/src/libs/ifc/xml/vabstractpattern.cpp index 1dbac7ddd..522c481e0 100644 --- a/src/libs/ifc/xml/vabstractpattern.cpp +++ b/src/libs/ifc/xml/vabstractpattern.cpp @@ -207,13 +207,10 @@ namespace void ReadExpressionAttribute(QVector &expressions, const QDomElement &element, const QString &attribute) { VFormulaField formula; - try + formula.expression = VDomDocument::GetParametrEmptyString(element, attribute); + + if (formula.expression.isEmpty()) { - formula.expression = VDomDocument::GetParametrString(element, attribute); - } - catch (VExceptionEmptyParameter &e) - { - Q_UNUSED(e) return; } diff --git a/src/libs/ifc/xml/vdomdocument.cpp b/src/libs/ifc/xml/vdomdocument.cpp index 66be6fa3f..d0763f14c 100644 --- a/src/libs/ifc/xml/vdomdocument.cpp +++ b/src/libs/ifc/xml/vdomdocument.cpp @@ -456,16 +456,9 @@ QString VDomDocument::GetParametrString(const QDomElement &domElement, const QSt //--------------------------------------------------------------------------------------------------------------------- QString VDomDocument::GetParametrEmptyString(const QDomElement &domElement, const QString &name) { - QString result; - try - { - result = GetParametrString(domElement, name, ""); - } - catch(const VExceptionEmptyParameter &) - { - // do nothing - } - return result; + Q_ASSERT_X(not name.isEmpty(), Q_FUNC_INFO, "name of parametr is empty"); + Q_ASSERT_X(not domElement.isNull(), Q_FUNC_INFO, "domElement is null"); + return domElement.attribute(name); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vformat/vmeasurements.cpp b/src/libs/vformat/vmeasurements.cpp index 6bbd39e6f..455715a05 100644 --- a/src/libs/vformat/vmeasurements.cpp +++ b/src/libs/vformat/vmeasurements.cpp @@ -269,26 +269,8 @@ void VMeasurements::ReadMeasurements() const const QDomElement dom = list.at(i).toElement(); const QString name = GetParametrString(dom, AttrName); - - QString description; - try - { - description = GetParametrString(dom, AttrDescription); - } - catch (VExceptionEmptyParameter &e) - { - Q_UNUSED(e) - } - - QString fullName; - try - { - fullName = GetParametrString(dom, AttrFullName); - } - catch (VExceptionEmptyParameter &e) - { - Q_UNUSED(e) - } + const QString description = GetParametrEmptyString(dom, AttrDescription); + const QString fullName = GetParametrEmptyString(dom, AttrFullName); QSharedPointer meash; QSharedPointer tempMeash;