From 114bdfe9dd69371604b48e0320d7b4dd834fadc5 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 24 Jan 2018 14:06:21 +0200 Subject: [PATCH] Speed optimization for method VPattern::ElementsToParse(). --HG-- branch : develop --- src/app/valentina/xml/vpattern.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/app/valentina/xml/vpattern.cpp b/src/app/valentina/xml/vpattern.cpp index 853b1e5b4..bfc1188ce 100644 --- a/src/app/valentina/xml/vpattern.cpp +++ b/src/app/valentina/xml/vpattern.cpp @@ -64,6 +64,7 @@ #include #include #include +#include const QString VPattern::AttrReadOnly = QStringLiteral("readOnly"); @@ -74,6 +75,12 @@ QString FileComment() { return QString("Pattern created with Valentina v%1 (https://valentinaproject.bitbucket.io/).").arg(APP_VERSION_STR); } + +//--------------------------------------------------------------------------------------------------------------------- +void GatherCount(int &count, const int nodes) +{ + count += nodes; +} } //--------------------------------------------------------------------------------------------------------------------- @@ -534,17 +541,16 @@ void VPattern::RefreshCurves() //--------------------------------------------------------------------------------------------------------------------- int VPattern::ElementsToParse() const { - int count = elementsByTagName(TagArc).length(); - count += elementsByTagName(TagDetail).length(); - count += elementsByTagName(TagElArc).length(); - count += elementsByTagName(TagLine).length(); - count += elementsByTagName(TagSpline).length(); - count += elementsByTagName(TagOperation).length(); - count += elementsByTagName(TagPath).length(); - count += elementsByTagName(TagPoint).length(); - count += elementsByTagName(TagTools).length(); - count += elementsByTagName(TagIncrement).length(); - return count; + QVector tags({TagArc, TagDetail, TagElArc, TagLine, TagSpline, TagOperation, TagPath, TagPoint, + TagTools, TagIncrement + }); + + std::function TagsCount = [this](const QString &tagName) + { + return elementsByTagName(tagName).length(); + }; + + return QtConcurrent::blockingMappedReduced(tags, TagsCount, GatherCount); } //---------------------------------------------------------------------------------------------------------------------