path: root/src
diff options
authorGiuseppe D'Angelo <>2012-02-22 03:33:00 +0000
committerQt by Nokia <>2012-03-07 19:18:22 +0100
commiteb709333989a7e3d8eb662a0e167ac81ca19d882 (patch)
treed1f72265b583b06c9b16e75f1dc6ab89eed2da25 /src
parentaee8f7d81eaec36e7d406607644f8fce294f7e21 (diff)
QRegularExpression: add optimizations autotest
Exporting the counter that controls the optimization of a compiled pattern lets us to forcibly optimize all patterns. Therefore, two tests are now run: one with default optimization values and another one which always optimizes the pattern. The counter itself was renamed with a qt_ prefix and put inside the Qt compilation namespace (thanks to rohanpm for pointing it out). Change-Id: I56602433d37adc127772b2d0d2cdaf2e49d43c71 Reviewed-by: Rohan McGovern <> Reviewed-by: Thiago Macieira <>
Diffstat (limited to 'src')
1 files changed, 9 insertions, 5 deletions
diff --git a/src/corelib/tools/qregularexpression.cpp b/src/corelib/tools/qregularexpression.cpp
index 0252a30c89..0fa7d6459e 100644
--- a/src/corelib/tools/qregularexpression.cpp
+++ b/src/corelib/tools/qregularexpression.cpp
@@ -50,9 +50,6 @@
#include <pcre.h>
-// after how many usages we optimize the regexp
-static const unsigned int OPTIMIZE_AFTER_USE_COUNT = 10;
@@ -726,6 +723,13 @@ QT_BEGIN_NAMESPACE
contain any metacharacter that anchors the match at that point.
+// after how many usages we optimize the regexp
+Q_AUTOTEST_EXPORT unsigned int qt_qregularexpression_optimize_after_use_count = 10;
+static const unsigned int qt_qregularexpression_optimize_after_use_count = 10;
@@ -1012,7 +1016,7 @@ static bool isJitEnabled()
setting the studyData member variable to the result of the study. It gets
called by doMatch() every time a match is performed. As of now, the
optimizations on the pattern are performed after a certain number of usages
- (i.e. the OPTIMIZE_AFTER_USE_COUNT constant).
+ (i.e. the qt_qregularexpression_optimize_after_use_count constant).
Notice that although the method is protected by a mutex, one thread may
invoke this function and return immediately (i.e. not study the pattern,
@@ -1028,7 +1032,7 @@ pcre16_extra *QRegularExpressionPrivate::optimizePattern()
QMutexLocker lock(&mutex);
- if (studyData || (++usedCount != OPTIMIZE_AFTER_USE_COUNT))
+ if (studyData || (++usedCount != qt_qregularexpression_optimize_after_use_count))
return studyData;
static const bool enableJit = isJitEnabled();