From eb709333989a7e3d8eb662a0e167ac81ca19d882 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Wed, 22 Feb 2012 03:33:00 +0000 Subject: 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 --- src/corelib/tools/qregularexpression.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/corelib/tools/qregularexpression.cpp') 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 -// after how many usages we optimize the regexp -static const unsigned int OPTIMIZE_AFTER_USE_COUNT = 10; - QT_BEGIN_NAMESPACE /*! @@ -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 +#ifdef QT_BUILD_INTERNAL +Q_AUTOTEST_EXPORT unsigned int qt_qregularexpression_optimize_after_use_count = 10; +#else +static const unsigned int qt_qregularexpression_optimize_after_use_count = 10; +#endif // QT_BUILD_INTERNAL + /*! \internal */ @@ -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(); -- cgit v1.2.3