aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4regexp.cpp
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2024-01-26 07:46:39 +0000
committerFabian Kosmale <fabian.kosmale@qt.io>2024-01-26 09:13:55 +0000
commit34f39f670281fdce22a402508b1a8e55be6e9fa2 (patch)
treef16748e79eda6aa9239663aa2b5e72ccb420090c /src/qml/jsruntime/qv4regexp.cpp
parent6963c0f6b0a00e9dfd0831f695c5aa5a25a85afe (diff)
Revert "RegExp: Do on demand JIT compilation"
This reverts commit 04820be3011395bd5cb13dea8f81c9b9bca4da8f. Reason for revert: Caused QTBUG-121535 Fixes: QTBUG-121535 Change-Id: Ie65a98bc8dd07e836cf663695d9259014581bda6 Reviewed-by: Jani Heikkinen <jani.heikkinen@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4regexp.cpp')
-rw-r--r--src/qml/jsruntime/qv4regexp.cpp76
1 files changed, 26 insertions, 50 deletions
diff --git a/src/qml/jsruntime/qv4regexp.cpp b/src/qml/jsruntime/qv4regexp.cpp
index 1876b29c3e..be7ff77603 100644
--- a/src/qml/jsruntime/qv4regexp.cpp
+++ b/src/qml/jsruntime/qv4regexp.cpp
@@ -9,10 +9,6 @@
using namespace QV4;
-#if ENABLE(YARR_JIT)
-static constexpr quint8 RegexpJitThreshold = 5;
-#endif
-
static JSC::RegExpFlags jscFlags(uint flags)
{
JSC::RegExpFlags jscFlags = JSC::NoFlags;
@@ -44,51 +40,12 @@ uint RegExp::match(const QString &string, int start, uint *matchOffsets)
if (!isValid())
return JSC::Yarr::offsetNoMatch;
-#if ENABLE(YARR_JIT)
- auto *priv = d();
-
- auto regenerateByteCode = [](Heap::RegExp *regexp) {
- JSC::Yarr::ErrorCode error = JSC::Yarr::ErrorCode::NoError;
- JSC::Yarr::YarrPattern yarrPattern(WTF::String(*regexp->pattern), jscFlags(regexp->flags),
- error);
-
- // As we successfully parsed the pattern before, we should still be able to.
- Q_ASSERT(error == JSC::Yarr::ErrorCode::NoError);
-
- regexp->byteCode = JSC::Yarr::byteCompile(
- yarrPattern,
- regexp->internalClass->engine->bumperPointerAllocator).release();
- };
- auto removeJitCode = [](Heap::RegExp *regexp) {
- delete regexp->jitCode;
- regexp->jitCode = nullptr;
- regexp->jitFailed = true;
- };
- if (!(priv->jitCode || priv->jitFailed)) {
- if (string.length() > 1024 || priv->matchCount++ == RegexpJitThreshold) {
- auto *engine = priv->internalClass->engine;
- if (engine->canJIT()) {
- JSC::Yarr::ErrorCode error = JSC::Yarr::ErrorCode::NoError;
- JSC::Yarr::YarrPattern yarrPattern(WTF::String(*priv->pattern), jscFlags(priv->flags), error);
- if (!yarrPattern.m_containsBackreferences) {
- priv->jitCode = new JSC::Yarr::YarrCodeBlock;
- JSC::VM *vm = static_cast<JSC::VM *>(engine);
- JSC::Yarr::jitCompile(yarrPattern, JSC::Yarr::Char16, vm, *priv->jitCode);
- }
- }
- if (!priv->hasValidJITCode())
- removeJitCode(priv);
- }
- // Note: We can't throw away the byte code as the JIT can't handle everything and
- // might return offsetJITFail
- }
-#endif
-
WTF::String s(string);
#if ENABLE(YARR_JIT)
+ static const uint offsetJITFail = std::numeric_limits<unsigned>::max() - 1;
+ auto *priv = d();
if (priv->hasValidJITCode()) {
- static const uint offsetJITFail = std::numeric_limits<unsigned>::max() - 1;
uint ret = JSC::Yarr::offsetNoMatch;
#if ENABLE(YARR_JIT_ALL_PARENS_EXPRESSIONS)
char buffer[8192];
@@ -101,10 +58,19 @@ uint RegExp::match(const QString &string, int start, uint *matchOffsets)
if (ret != offsetJITFail)
return ret;
- removeJitCode(priv);
// JIT failed. We need byteCode to run the interpreter.
- Q_ASSERT(!priv->byteCode);
- regenerateByteCode(priv);
+ if (!priv->byteCode) {
+ JSC::Yarr::ErrorCode error = JSC::Yarr::ErrorCode::NoError;
+ JSC::Yarr::YarrPattern yarrPattern(WTF::String(*priv->pattern), jscFlags(priv->flags),
+ error);
+
+ // As we successfully parsed the pattern before, we should still be able to.
+ Q_ASSERT(error == JSC::Yarr::ErrorCode::NoError);
+
+ priv->byteCode = JSC::Yarr::byteCompile(
+ yarrPattern,
+ priv->internalClass->engine->bumperPointerAllocator).release();
+ }
}
#endif // ENABLE(YARR_JIT)
@@ -209,15 +175,25 @@ void Heap::RegExp::init(ExecutionEngine *engine, const QString &pattern, uint fl
this->flags = flags;
valid = false;
- jitFailed = false;
- matchCount = 0;
JSC::Yarr::ErrorCode error = JSC::Yarr::ErrorCode::NoError;
JSC::Yarr::YarrPattern yarrPattern(WTF::String(pattern), jscFlags(flags), error);
if (error != JSC::Yarr::ErrorCode::NoError)
return;
subPatternCount = yarrPattern.m_numSubpatterns;
+#if ENABLE(YARR_JIT)
+ if (!yarrPattern.m_containsBackreferences && engine->canJIT()) {
+ jitCode = new JSC::Yarr::YarrCodeBlock;
+ JSC::VM *vm = static_cast<JSC::VM *>(engine);
+ JSC::Yarr::jitCompile(yarrPattern, JSC::Yarr::Char16, vm, *jitCode);
+ }
+#else
Q_UNUSED(engine);
+#endif
+ if (hasValidJITCode()) {
+ valid = true;
+ return;
+ }
byteCode = JSC::Yarr::byteCompile(yarrPattern, internalClass->engine->bumperPointerAllocator).release();
if (byteCode)
valid = true;