From 7dc29c0f008b5f82805ec14ee413df10191445a7 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 20 Jan 2018 12:35:43 +0200 Subject: [PATCH] Speed optimization for method VCommonSettings::GetCurveApproximationScale(). --HG-- branch : develop --- src/libs/vmisc/vcommonsettings.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/libs/vmisc/vcommonsettings.cpp b/src/libs/vmisc/vcommonsettings.cpp index 22e3e6b26..b5c568aa3 100644 --- a/src/libs/vmisc/vcommonsettings.cpp +++ b/src/libs/vmisc/vcommonsettings.cpp @@ -95,6 +95,9 @@ const QString settingLabelUserDateFormats = QStringLiteral("label/userDateFormat const QString settingLabelTimeFormat = QStringLiteral("label/timeFormat"); const QString settingLabelUserTimeFormats = QStringLiteral("label/userTimeFormats"); +// Reading settings file is very expensive, cache curve approximation to speed up getting value +qreal curveApproximationCached = -1; + //--------------------------------------------------------------------------------------------------------------------- QStringList ClearFormats(const QStringList &predefinedFormats, QStringList formats) { @@ -1006,16 +1009,21 @@ void VCommonSettings::SetUserDefinedTimeFormats(const QStringList &formats) //--------------------------------------------------------------------------------------------------------------------- qreal VCommonSettings::GetCurveApproximationScale() const { - bool ok = false; - const qreal scale = value(settingPatternCurveApproximationScale, defCurveApproximationScale).toDouble(&ok); - if (ok && scale >= minCurveApproximationScale && scale <= maxCurveApproximationScale) + if (curveApproximationCached < 0) { - return scale; - } - else - { - return defCurveApproximationScale; + bool ok = false; + const qreal scale = value(settingPatternCurveApproximationScale, defCurveApproximationScale).toDouble(&ok); + if (ok && scale >= minCurveApproximationScale && scale <= maxCurveApproximationScale) + { + curveApproximationCached = scale; + } + else + { + curveApproximationCached = defCurveApproximationScale; + } } + + return curveApproximationCached; } //--------------------------------------------------------------------------------------------------------------------- @@ -1024,6 +1032,7 @@ void VCommonSettings::SetCurveApproximationScale(qreal value) if (value >= minCurveApproximationScale && value <= maxCurveApproximationScale) { setValue(settingPatternCurveApproximationScale, value); + curveApproximationCached = value; } }