Speed optimization for method VAbstractPattern::ListMeasurements().

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-01-24 13:16:29 +02:00
parent 4177924a6f
commit a91b1a3816
11 changed files with 66 additions and 67 deletions

View File

@ -227,7 +227,8 @@ ISYSTEM += \
-isystem "$$[QT_INSTALL_HEADERS]/QtPrintSupport" \ -isystem "$$[QT_INSTALL_HEADERS]/QtPrintSupport" \
-isystem "$$[QT_INSTALL_HEADERS]/QtSvg" \ -isystem "$$[QT_INSTALL_HEADERS]/QtSvg" \
-isystem "$$[QT_INSTALL_HEADERS]/QtNetwork" \ -isystem "$$[QT_INSTALL_HEADERS]/QtNetwork" \
-isystem "$$[QT_INSTALL_HEADERS]/QtTest" -isystem "$$[QT_INSTALL_HEADERS]/QtTest" \
-isystem "$$[QT_INSTALL_HEADERS]/QtConcurrent"
} else { } else {
ISYSTEM += \ ISYSTEM += \
-isystem "$$[QT_INSTALL_LIBS]/QtWidgets.framework/Headers/" \ -isystem "$$[QT_INSTALL_LIBS]/QtWidgets.framework/Headers/" \
@ -247,7 +248,9 @@ ISYSTEM += \
-isystem "$$[QT_INSTALL_LIBS]/QtNetwork.framework/Headers/" \ -isystem "$$[QT_INSTALL_LIBS]/QtNetwork.framework/Headers/" \
-isystem "$$[QT_INSTALL_LIBS]/QtNetwork.framework/Versions/5/Headers/" \ -isystem "$$[QT_INSTALL_LIBS]/QtNetwork.framework/Versions/5/Headers/" \
-isystem "$$[QT_INSTALL_LIBS]/QtTest.framework/Headers/" \ -isystem "$$[QT_INSTALL_LIBS]/QtTest.framework/Headers/" \
-isystem "$$[QT_INSTALL_LIBS]/QtTest.framework/Versions/5/Headers/" -isystem "$$[QT_INSTALL_LIBS]/QtTest.framework/Versions/5/Headers/" \
-isystem "$$[QT_INSTALL_LIBS]/QtConcurrent.framework/Headers/" \
-isystem "$$[QT_INSTALL_LIBS]/QtConcurrent.framework/Versions/5/Headers/"
} }
# Usefull GCC warnings keys. # Usefull GCC warnings keys.

View File

@ -15,7 +15,7 @@ Vcs-Browser: https://bitbucket.org/dismine/valentina
Package: valentina Package: valentina
Architecture: i386 amd64 Architecture: i386 amd64
Depends: libc6 (>= 2.4), libgcc1 (>= 1:4.1.1), libqt5core5a (>= 5.2.0) | libqt5core5 (>= 5.2.0), libqt5gui5 (>= 5.2.0) | libqt5gui5-gles (>= 5.2.0), libqt5printsupport5 (>= 5.2.0), libqt5svg5 (>= 5.2.0), libqt5widgets5 (>= 5.2.0), libqt5xml5 (>= 5.2.0), libqt5xmlpatterns5 (>= 5.2.0), libstdc++6 (>= 4.6), xpdf Depends: libc6 (>= 2.4), libgcc1 (>= 1:4.1.1), libqt5core5a (>= 5.2.0) | libqt5core5 (>= 5.2.0), libqt5gui5 (>= 5.2.0) | libqt5gui5-gles (>= 5.2.0), libqt5printsupport5 (>= 5.2.0), libqt5svg5 (>= 5.2.0), libqt5widgets5 (>= 5.2.0), libqt5xml5 (>= 5.2.0), libqt5xmlpatterns5 (>= 5.2.0), libqt5concurrent5(>= 5.2.0), libstdc++6 (>= 4.6), xpdf
Conflicts: seamly2d Conflicts: seamly2d
Description: Pattern making program. Description: Pattern making program.
Valentina is a cross-platform patternmaking program which allows designers Valentina is a cross-platform patternmaking program which allows designers

2
dist/debian/control vendored
View File

@ -15,7 +15,7 @@ Vcs-Browser: https://bitbucket.org/dismine/valentina
Package: valentina Package: valentina
Architecture: i386 amd64 Architecture: i386 amd64
Depends: libc6 (>= 2.4), libgcc1 (>= 1:4.1.1), libqt5core5a (>= 5.2.0) | libqt5core5 (>= 5.2.0), libqt5gui5 (>= 5.2.0) | libqt5gui5-gles (>= 5.2.0), libqt5printsupport5 (>= 5.2.0), libqt5svg5 (>= 5.2.0), libqt5widgets5 (>= 5.2.0), libqt5xml5 (>= 5.2.0), libqt5xmlpatterns5 (>= 5.2.0), libstdc++6 (>= 4.6), xpdf Depends: libc6 (>= 2.4), libgcc1 (>= 1:4.1.1), libqt5core5a (>= 5.2.0) | libqt5core5 (>= 5.2.0), libqt5gui5 (>= 5.2.0) | libqt5gui5-gles (>= 5.2.0), libqt5printsupport5 (>= 5.2.0), libqt5svg5 (>= 5.2.0), libqt5widgets5 (>= 5.2.0), libqt5xml5 (>= 5.2.0), libqt5xmlpatterns5 (>= 5.2.0), libqt5concurrent5(>= 5.2.0), libstdc++6 (>= 4.6), xpdf
Conflicts: seamly2d Conflicts: seamly2d
Description: Pattern making program. Description: Pattern making program.
Valentina is a cross-platform patternmaking program which allows designers Valentina is a cross-platform patternmaking program which allows designers

View File

@ -34,6 +34,7 @@ CDEPEND="
dev-qt/qtxmlpatterns:5 dev-qt/qtxmlpatterns:5
dev-qt/qtprintsupport:5 dev-qt/qtprintsupport:5
dev-qt/qtnetwork:5 dev-qt/qtnetwork:5
dev-qt/qtconcurrent:5
app-text/poppler" app-text/poppler"
RDEPEND="${CDEPEND}" RDEPEND="${CDEPEND}"
DEPEND="${CDEPEND} DEPEND="${CDEPEND}

View File

@ -17,6 +17,7 @@ BuildRequires: pkgconfig(Qt5Network)
BuildRequires: pkgconfig(Qt5PrintSupport) BuildRequires: pkgconfig(Qt5PrintSupport)
BuildRequires: pkgconfig(Qt5Widgets) BuildRequires: pkgconfig(Qt5Widgets)
BuildRequires: pkgconfig(Qt5Xml) BuildRequires: pkgconfig(Qt5Xml)
BuildRequires: pkgconfig(Qt5Concurrent)
BuildRequires: qt5-qtxmlpatterns-devel >= 5.2.0 BuildRequires: qt5-qtxmlpatterns-devel >= 5.2.0
BuildRequires: qt5-qtsvg-devel >= 5.2.0 BuildRequires: qt5-qtsvg-devel >= 5.2.0
BuildRequires: qt5-qttools-devel >= 5.2.0 BuildRequires: qt5-qttools-devel >= 5.2.0

View File

@ -7,7 +7,7 @@
# File with common stuff for whole project # File with common stuff for whole project
include(../../../common.pri) include(../../../common.pri)
QT += core gui widgets network xml xmlpatterns printsupport svg QT += core gui widgets network xml xmlpatterns printsupport svg concurrent
# Name of binary file # Name of binary file
TARGET = tape TARGET = tape

View File

@ -11,7 +11,7 @@ include(../../../common.pri)
# Here we don't see "network" library, but, i think, "printsupport" depend on this library, so we still need this # Here we don't see "network" library, but, i think, "printsupport" depend on this library, so we still need this
# library in installer. # library in installer.
QT += core gui widgets xml svg printsupport xmlpatterns QT += core gui widgets xml svg printsupport xmlpatterns concurrent
# We want create executable file # We want create executable file
TEMPLATE = app TEMPLATE = app
@ -292,6 +292,7 @@ win32:*g++* {
$$[QT_INSTALL_BINS]/icuin*.dll \ # Different name for different Qt releases $$[QT_INSTALL_BINS]/icuin*.dll \ # Different name for different Qt releases
$$[QT_INSTALL_BINS]/icuuc*.dll \ # Different name for different Qt releases $$[QT_INSTALL_BINS]/icuuc*.dll \ # Different name for different Qt releases
$$[QT_INSTALL_BINS]/Qt5Core.dll \ $$[QT_INSTALL_BINS]/Qt5Core.dll \
$$[QT_INSTALL_BINS]/Qt5Concurrent.dll \
$$[QT_INSTALL_BINS]/Qt5Gui.dll \ $$[QT_INSTALL_BINS]/Qt5Gui.dll \
$$[QT_INSTALL_BINS]/Qt5Network.dll \ $$[QT_INSTALL_BINS]/Qt5Network.dll \
$$[QT_INSTALL_BINS]/Qt5PrintSupport.dll \ $$[QT_INSTALL_BINS]/Qt5PrintSupport.dll \

View File

@ -8,7 +8,7 @@
include(../../../common.pri) include(../../../common.pri)
# Library work with xml. # Library work with xml.
QT += xml xmlpatterns printsupport QT += xml xmlpatterns printsupport concurrent
# We don't need gui library. # We don't need gui library.
QT -= gui QT -= gui

View File

@ -38,6 +38,9 @@
#include <QStringData> #include <QStringData>
#include <QStringDataPtr> #include <QStringDataPtr>
#include <QtDebug> #include <QtDebug>
#include <QtConcurrentMap>
#include <QFuture>
#include <QtConcurrentRun>
#include "../exception/vexceptionemptyparameter.h" #include "../exception/vexceptionemptyparameter.h"
#include "../exception/vexceptionobjecterror.h" #include "../exception/vexceptionobjecterror.h"
@ -219,6 +222,19 @@ void ReadExpressionAttribute(QVector<VFormulaField> &expressions, const QDomElem
expressions.append(formula); expressions.append(formula);
} }
//---------------------------------------------------------------------------------------------------------------------
QList<QString> GetTokens(const VFormulaField &formula)
{
QScopedPointer<qmu::QmuTokenParser> cal(new qmu::QmuTokenParser(formula.expression, false, false));
return cal->GetTokens().values();
}
//---------------------------------------------------------------------------------------------------------------------
void GatherTokens(QSet<QString> &tokens, const QList<QString> &tokenList)
{
tokens = tokens.unite(tokenList.toSet());
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -236,50 +252,22 @@ VAbstractPattern::VAbstractPattern(QObject *parent)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QStringList VAbstractPattern::ListMeasurements() const QStringList VAbstractPattern::ListMeasurements() const
{ {
const QFuture<QStringList> futureIncrements = QtConcurrent::run(this, &VAbstractPattern::ListIncrements);
const QList<QString> tokens = QtConcurrent::blockingMappedReduced(ListExpressions(), GetTokens,
GatherTokens).toList();
QSet<QString> measurements; QSet<QString> measurements;
QSet<QString> others; QSet<QString> others = futureIncrements.result().toSet();
const QStringList increments = ListIncrements(); foreach (const QString &token, tokens)
for (int i=0; i < increments.size(); ++i)
{ {
others.insert(increments.at(i)); if (token == QChar('-') || measurements.contains(token) || others.contains(token))
}
const QVector<VFormulaField> expressions = ListExpressions();
for (int i=0; i < expressions.size(); ++i)
{
// Eval formula
QScopedPointer<qmu::QmuTokenParser> cal(new qmu::QmuTokenParser(expressions.at(i).expression, false, false));
const QMap<int, QString> tokens = cal->GetTokens();// Tokens (variables, measurements)
delete cal.take();
const QList<QString> tValues = tokens.values();
for (int j = 0; j < tValues.size(); ++j)
{ {
if (tValues.at(j) == QChar('-')) continue;
{
continue;
}
if (measurements.contains(tValues.at(j)))
{
continue;
}
if (others.contains(tValues.at(j)))
{
continue;
}
if (IsVariable(tValues.at(j)) || IsFunction(tValues.at(j)))
{
others.insert(tValues.at(j));
}
else
{
measurements.insert(tValues.at(j));
}
} }
IsVariable(token) || IsFunction(token) ? others.insert(token) : measurements.insert(token);
} }
return QStringList(measurements.toList()); return QStringList(measurements.toList());
@ -1731,15 +1719,10 @@ QStringList VAbstractPattern::ListIncrements() const
const QDomNodeList list = elementsByTagName(type); const QDomNodeList list = elementsByTagName(type);
for (int i=0; i < list.size(); ++i) for (int i=0; i < list.size(); ++i)
{ {
const QDomElement dom = list.at(i).toElement(); const QString name = GetParametrEmptyString(list.at(i).toElement(), AttrName);
if (not name.isEmpty())
try
{ {
increments.append(GetParametrString(dom, AttrName)); increments.append(name);
}
catch (VExceptionEmptyParameter &e)
{
Q_UNUSED(e)
} }
} }
}; };
@ -1753,20 +1736,30 @@ QStringList VAbstractPattern::ListIncrements() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QVector<VFormulaField> VAbstractPattern::ListExpressions() const QVector<VFormulaField> VAbstractPattern::ListExpressions() const
{ {
QVector<VFormulaField> list;
// If new tool bring absolutely new type and has formula(s) create new method to cover it. // If new tool bring absolutely new type and has formula(s) create new method to cover it.
// Note. Tool Union Details also contains formulas, but we don't use them for union and keep only to simplifying // Note. Tool Union Details also contains formulas, but we don't use them for union and keep only to simplifying
// working with nodes. Same code for saving reading. // working with nodes. Same code for saving reading.
list << ListPointExpressions(); auto futurePointExpressions = QtConcurrent::run(this, &VAbstractPattern::ListPointExpressions);
list << ListArcExpressions(); auto futureArcExpressions = QtConcurrent::run(this, &VAbstractPattern::ListArcExpressions);
list << ListElArcExpressions(); auto futureElArcExpressions = QtConcurrent::run(this, &VAbstractPattern::ListElArcExpressions);
list << ListSplineExpressions(); auto futureSplineExpressions = QtConcurrent::run(this, &VAbstractPattern::ListSplineExpressions);
list << ListIncrementExpressions(); auto futureIncrementExpressions = QtConcurrent::run(this, &VAbstractPattern::ListIncrementExpressions);
list << ListOperationExpressions(); auto futureOperationExpressions = QtConcurrent::run(this, &VAbstractPattern::ListOperationExpressions);
list << ListPathExpressions(); auto futurePathExpressions = QtConcurrent::run(this, &VAbstractPattern::ListPathExpressions);
list << ListPieceExpressions(); auto futurePieceExpressions = QtConcurrent::run(this, &VAbstractPattern::ListPieceExpressions);
list << ListFinalMeasurementsExpressions(); auto futureFinalMeasurementsExpressions = QtConcurrent::run(this,
&VAbstractPattern::ListFinalMeasurementsExpressions);
QVector<VFormulaField> list;
list << futurePointExpressions.result();
list << futureArcExpressions.result();
list << futureElArcExpressions.result();
list << futureSplineExpressions.result();
list << futureIncrementExpressions.result();
list << futureOperationExpressions.result();
list << futurePathExpressions.result();
list << futurePieceExpressions.result();
list << futureFinalMeasurementsExpressions.result();
return list; return list;
} }

View File

@ -4,7 +4,7 @@
# #
#------------------------------------------------- #-------------------------------------------------
QT += testlib widgets printsupport QT += testlib widgets printsupport concurrent
QT -= gui QT -= gui

View File

@ -4,7 +4,7 @@
# #
#------------------------------------------------- #-------------------------------------------------
QT += core testlib gui printsupport xml xmlpatterns QT += core testlib gui printsupport xml xmlpatterns concurrent
TARGET = ValentinaTests TARGET = ValentinaTests