From 61867fa2d7ed4bb88fa04d8ca6f60a9860736497 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 19 Jan 2021 13:25:10 +0200 Subject: [PATCH] Optimize a measurements file loading time. --- src/libs/ifc/xml/vdomdocument.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/libs/ifc/xml/vdomdocument.cpp b/src/libs/ifc/xml/vdomdocument.cpp index cd0733d4c..2d3efa581 100644 --- a/src/libs/ifc/xml/vdomdocument.cpp +++ b/src/libs/ifc/xml/vdomdocument.cpp @@ -232,7 +232,9 @@ bool LessThen(const QDomNode &element1, const QDomNode &element2) } return false; } -} + +Unit mUnitCached = Unit::LAST_UNIT_DO_NOT_USE; +} // namespace Q_LOGGING_CATEGORY(vXML, "v.xml") @@ -586,19 +588,18 @@ qreal VDomDocument::GetParametrDouble(const QDomElement &domElement, const QStri bool ok = false; qreal param = 0; - const QString message = QObject::tr("Can't convert toDouble parameter"); try { QString parametr = GetParametrString(domElement, name, defValue); param = parametr.replace(QChar(','), QChar('.')).toDouble(&ok); if (ok == false) { - throw VExceptionConversionError(message, name); + throw VExceptionConversionError(QObject::tr("Can't convert toDouble parameter"), name); } } catch (const VExceptionEmptyParameter &e) { - VExceptionConversionError excep(message, name); + VExceptionConversionError excep(QObject::tr("Can't convert toDouble parameter"), name); excep.AddMoreInformation(e.ErrorMessage()); throw excep; } @@ -638,14 +639,17 @@ quint32 VDomDocument::GetParametrId(const QDomElement &domElement) //--------------------------------------------------------------------------------------------------------------------- Unit VDomDocument::MUnit() const { - Unit unit = StrToUnits(UniqueTagText(TagUnit, unitCM)); - - if (unit == Unit::Px) + if (mUnitCached == Unit::LAST_UNIT_DO_NOT_USE) { - unit = Unit::Cm; + mUnitCached = StrToUnits(UniqueTagText(TagUnit, unitCM)); + + if (mUnitCached == Unit::Px) + { + mUnitCached = Unit::Cm; + } } - return unit; + return mUnitCached; } //---------------------------------------------------------------------------------------------------------------------