diff options
author | aavit <qt-info@nokia.com> | 2010-09-08 11:29:43 (GMT) |
---|---|---|
committer | aavit <qt-info@nokia.com> | 2010-09-08 11:29:43 (GMT) |
commit | 6d4003b0fd742ee2be2e536091d5b65d72d01ce0 (patch) | |
tree | 05dc0d1e7bd694cc4630d44317954bcb3e55b5e9 /tests | |
parent | 1743a8bea43066c52cf07f6c8a859c3d9ddb65da (diff) | |
download | Qt-6d4003b0fd742ee2be2e536091d5b65d72d01ce0.zip Qt-6d4003b0fd742ee2be2e536091d5b65d72d01ce0.tar.gz Qt-6d4003b0fd742ee2be2e536091d5b65d72d01ce0.tar.bz2 |
Shave 25% off test time by smarter qps script parsing
Diffstat (limited to 'tests')
-rw-r--r-- | tests/arthur/common/paintcommands.cpp | 27 | ||||
-rw-r--r-- | tests/arthur/common/paintcommands.h | 2 |
2 files changed, 26 insertions, 3 deletions
diff --git a/tests/arthur/common/paintcommands.cpp b/tests/arthur/common/paintcommands.cpp index 70d419e..1d7b810 100644 --- a/tests/arthur/common/paintcommands.cpp +++ b/tests/arthur/common/paintcommands.cpp @@ -185,6 +185,7 @@ int PaintCommands::translateEnum(const char *table[], const QString &pattern, in QList<PaintCommands::PaintCommandInfos> PaintCommands::s_commandInfoTable = QList<PaintCommands::PaintCommandInfos>(); QList<QPair<QString,QStringList> > PaintCommands::s_enumsTable = QList<QPair<QString,QStringList> >(); +QMultiHash<QString, int> PaintCommands::s_commandHash; #define DECL_PAINTCOMMAND(identifier, method, regexp, syntax, sample) \ s_commandInfoTable << PaintCommandInfos(QLatin1String(identifier), &PaintCommands::method, QRegExp(regexp), \ @@ -627,6 +628,15 @@ void PaintCommands::staticInit() "\n - where vertices 1 to 4 defines the source quad and 5 to 8 the destination quad", "mapQuadToQuad 0.0 0.0 1.0 1.0 0.0 0.0 -1.0 -1.0"); + // populate the command lookup hash + for (int i=0; i<s_commandInfoTable.size(); i++) { + if (s_commandInfoTable.at(i).isSectionHeader() || + s_commandInfoTable.at(i).identifier == QLatin1String("comment") || + s_commandInfoTable.at(i).identifier == QLatin1String("noop")) + continue; + s_commandHash.insert(s_commandInfoTable.at(i).identifier, i); + } + // populate the enums list ADD_ENUMLIST("brush styles", brushStyleTable); ADD_ENUMLIST("pen styles", penStyleTable); @@ -686,12 +696,23 @@ void PaintCommands::insertAt(int commandIndex, const QStringList &newCommands) **********************************************************************************/ void PaintCommands::runCommand(const QString &scriptLine) { - staticInit(); - foreach (PaintCommandInfos command, s_commandInfoTable) - if (!command.isSectionHeader() && command.regExp.indexIn(scriptLine) >= 0) { + if (scriptLine.isEmpty()) { + command_noop(QRegExp()); + return; + } + if (scriptLine.startsWith('#')) { + command_comment(QRegExp()); + return; + } + QString firstWord = scriptLine.section(QRegExp("\\s"), 0, 0); + QList<int> indices = s_commandHash.values(firstWord); + foreach(int idx, indices) { + const PaintCommandInfos &command = s_commandInfoTable.at(idx); + if (command.regExp.indexIn(scriptLine) >= 0) { (this->*(command.paintMethod))(command.regExp); return; } + } qWarning("ERROR: unknown command or argument syntax error in \"%s\"", qPrintable(scriptLine)); } diff --git a/tests/arthur/common/paintcommands.h b/tests/arthur/common/paintcommands.h index aed4840..4d966b8 100644 --- a/tests/arthur/common/paintcommands.h +++ b/tests/arthur/common/paintcommands.h @@ -48,6 +48,7 @@ #include <qstringlist.h> #include <qpixmap.h> #include <qbrush.h> +#include <qhash.h> QT_FORWARD_DECLARE_CLASS(QPainter) QT_FORWARD_DECLARE_CLASS(QRegExp) @@ -329,6 +330,7 @@ public: static QList<PaintCommandInfos> s_commandInfoTable; static QList<QPair<QString,QStringList> > s_enumsTable; + static QMultiHash<QString, int> s_commandHash; }; #endif // PAINTCOMMANDS_H |