summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h
Commit message (Collapse)AuthorAgeFilesLines
* QRegularExpression: refactor pattern optimizationGiuseppe D'Angelo2018-06-221-79/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | After the move to PCRE2, optimizing patterns has been a thorn in the side due to the fact that PCRE2's JIT compiler modifies the pattern object itself (instead of returning a new set of data, like PCRE1 did). To make this fit with the existing behavior, a read/write lock was introduced, with the read part locking when matching and the write when compiling (or JIT-compiling) the pattern. This locking strategy however introduced a performance issue, as we needed: * to acquire a write lock to compile/optimize the pattern (incl. the common case where the pattern was already compiled, so bailing out immediately); * to acquire a read lock during the actual match, to prevent some other thread from optimizing the pattern under our nose. This was due to the "lazy" optimization policy of QRegularExpression -- optimize a pattern after a certain number of usages. The excessive amount of locking effectively limited scalability. Simplify the code, and drop that policy altogether: since JIT compiling in PCRE2 is faster and pretty much "always recommended", just always do it for any pattern (unless it gets disabled via env variables) when compiling it. This allows to go back to a plain QMutex, and now the actual matching doesn't require acquiring any locks any longer. Of course, there is still a mutex acquired just before matching for checking whether the pattern needs recompiling in the first place; this can probably be further optimized via double-checked locking (using atomics), but not doing it right now. This shift makes a couple of pattern options controlling optimization useless, and allows to centralize the 3 QRegularExpression tests (which were actually the very same test, just setting slightly different optimizations strategies). While at it, install a stress-test for threading, with the idea of running it under TSAN or helgrind to catch bugs in QRegularExpression's locking. [ChangeLog][Important Behavior Changes][QRegularExpression] Regular expressions are now automatically optimized (including JIT compiling) on their first usage. The pattern options OptimizeOnFirstUsageOption and DontAutomaticallyOptimizeOption no longer have any effect, and will get removed in a future version of Qt. QRegularExpression::optimize() can be still used to compile and optimize the regular expression in advance (before any match), if needed. Task-number: QTBUG-66781 Change-Id: Ia0e97208ae78255fe811b78029ed01c204e47bd2 Reviewed-by: David Faure <david.faure@kdab.com>
* Add wildcard-to-regexp support to QRegularExpressionSamuel Gaist2018-03-301-0/+5
| | | | | | | | | | | | | | | | | | This method will make QRegularExpression on par with QRegExp and will allow to replace this class when a wildcard expression can be set through an API (e.g. QSortFilterProxyModel::setFilterWildcard). For other use cases, see QTBUG-34052. [ChangeLog][QRegularExpression] Implemented support for wildcard patterns. Warning: QRegularExpression might not give the exact same result as QRegExp as its implementation follows strictly the glob patterns definition for the wildcard expressions. Change-Id: I5ed4617ca679159430c3d46da3449f6b3100e366 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
* Updated license headersJani Heikkinen2016-01-211-16/+11
| | | | | | | | | | | | | From Qt 5.7 -> tools & applications are lisenced under GPL v3 with some exceptions, see http://blog.qt.io/blog/2016/01/13/new-agreement-with-the-kde-free-qt-foundation/ Updated license headers to use new GPL-EXCEPT header instead of LGPL21 one (in those files which will be under GPL 3 with exceptions) Change-Id: I42a473ddc97101492a60b9287d90979d9eb35ae1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
* QRegularExpression: fix matching over QStringRefsGiuseppe D'Angelo2015-08-181-0/+1
| | | | | | | | | | | | | | | | | | | | | | | Playing with the offset argument of pcre_exec is not equivalent to adjusting the pointer to the subject string. In particular, PCRE can go behind the offset to check for lookbehinds or "transition" metacharacters (\b, \B, etc.). This made the code that deals with QStringRefs not matching in behavior with the corresponding code dealing with QStrings. For instance, QString subject("Miss"); QRegularExpression re("(?<=M)iss"); re.match(subject.mid(1)); // doesn't match re.match(subject.midRef(1)); // matches!!! Instead, actually adjust the pointer to the subject string so that the behavior is identical. A broken test that relied on the equivalence is also removed. Change-Id: If96333241ef59621d7f5a6a170ebd0a186844874 Reviewed-by: Volker Krause <volker.krause@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Update copyright headersJani Heikkinen2015-02-111-6/+6
| | | | | | | | | | | | | | | | | | Qt copyrights are now in The Qt Company, so we could update the source code headers accordingly. In the same go we should also fix the links to point to qt.io. Outdated header.LGPL removed (use header.LGPL21 instead) Old header.LGPL3 renamed to header.LGPL3-COMM to match actual licensing combination. New header.LGPL-COMM taken in the use file which were using old header.LGPL3 (src/plugins/platforms/android/extract.cpp) Added new header.LGPL3 containing Commercial + LGPLv3 + GPLv2 license combination Change-Id: I6f49b819a8a20cc4f88b794a8f6726d975e8ffbe Reviewed-by: Matti Paaso <matti.paaso@theqtcompany.com>
* Update license headers and add new license filesMatti Paaso2014-09-241-18/+10
| | | | | | | | | - Renamed LICENSE.LGPL to LICENSE.LGPLv21 - Added LICENSE.LGPLv3 - Removed LICENSE.GPL Change-Id: Iec3406e3eb3f133be549092015cefe33d259a3f2 Reviewed-by: Iikka Eklund <iikka.eklund@digia.com>
* QRegularExpression: print a warning if (?J) is used in a patternGiuseppe D'Angelo2013-02-121-0/+2
| | | | | | | | | (?J) inside a pattern string can be used to allow or disallow duplicated capturing group names in the pattern string itself. Although PCRE supports duplicated names, in Qt we don't yet. Change-Id: I21cd0c41273cd7ef42870ced3a0fad6ba7035cbc Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRegularExpression: add method for extracting the capturing group namesGiuseppe D'Angelo2013-02-051-0/+2
| | | | | | | | | | | | | | | | It may be useful to know which named capturing groups are defined in an regular expression, and for each of them, what's the corresponding index. This commit adds the needed method to QRegularExpression. Note that extracting the information doesn't happen while holding the mutex in the private -- pcre_fullinfo just reads information from the compiled pattern, so that's thread-safe. Task-number: QTBUG-29079 Change-Id: I50c00ee860f06427c2e6ea10417d5c0733cc8303 Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Introduce default ctors for QRegularExpressionMatch(Iterator)Giuseppe D'Angelo2013-01-141-0/+1
| | | | | | | | This allows to put them in containers, and to enable subsequent features for QString. Change-Id: I3b3fe695ffe6930331ed9f670738376722e0fc36 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Change copyrights from Nokia to DigiaIikka Eklund2012-09-221-23/+23
| | | | | | | | Change copyrights and license headers from Nokia to Digia Change-Id: If1cc974286d29fd01ec6c19dd4719a67f4c3f00e Reviewed-by: Lars Knoll <lars.knoll@digia.com> Reviewed-by: Sergio Ahumada <sergio.ahumada@digia.com>
* QRegularExpression: minor fix to captureIndexForNameGiuseppe D'Angelo2012-03-081-0/+2
| | | | | | | | | | | | Although passing a null pointer to pcre16_get_stringnumber for the compiled pattern should simply make it error out, it's actually an undocumented behaviour, so let's stay safe and add an explicit check. Tests for this codepath are added. Change-Id: Ifd9c87874f6812ba487104ec1a5bbc83c3b16761 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRegularExpression: improve JIT memory handlingGiuseppe D'Angelo2012-03-081-0/+2
| | | | | | | | | | | | | | | | | PCRE's JIT uses by default 32K on the pcre_exec caller's stack. This is fine for most situations, but in some cases (esp. patterns with lot of recursion) more memory is required. Therefore, if a match execution fails due to exhausting JIT memory, we let PCRE allocate up to 512KB to be used for the JIT's stack. The pointer to the allocated memory is put in thread local storage (so it can be reused from the same thread, if needed, and automatically goes away when the thread dies). Change-Id: Ica5fb7d517068befff88ebb198a603a26ec5d8a7 Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRegularExpression: add optimizations autotestGiuseppe D'Angelo2012-03-071-0/+77
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 <rohan.mcgovern@nokia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>