aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4regexp_p.h
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-12-10 10:26:34 +0100
committerUlf Hermann <ulf.hermann@qt.io>2024-12-12 08:00:24 +0100
commitb4b691b040f2251820292a27bdcf01d4d7530bc6 (patch)
treeb44e3672f38dc53bb503fc336646ddc1ef050017 /src/qml/jsruntime/qv4regexp_p.h
parentc5b0fa28061fc3e99ce79ff9603d87791b41a197 (diff)
QtQml: Add some consistency to QV4::RegExp
The RegExp JIT should behave the same as the V4 JIT. In particular, it should honor the same JIT call threshold and not second guess any manually set thresholds. To do this we need to store the match count in 32 bits. In turn we can store the 5 flags we may have in 8 bits. To make this safe, pass typed flags to the initialization functions. Also, consider the flags when calculating hash values. Finally, in the init() function, we don't need to initialize members to zero, since that is already guaranteed by the memory manager. And we can delete the flagsAsString() method since it's unused. This requires shuffling some #includes into the places where they actually belong. [ChangeLog][QtQml] The JavaScript regular expression engine now honors QV4_JIT_CALL_THRESHOLD for its own JIT. If QV4_JIT_CALL_THRESHOLD is not set, it uses the JIT after 3 interpreted matches for any regular expression, rather than the previous 5. Matching a regular expression on a string longer than 1024 bytes counts as 3 matches. This is to retain the default behavior of JIT'ing regular expressions right away when encountering long strings. Task-number: QTBUG-131957 Change-Id: I269ccea55d34b191ef18d7cd5fccd4cad8aec7cd Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4regexp_p.h')
-rw-r--r--src/qml/jsruntime/qv4regexp_p.h37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/qml/jsruntime/qv4regexp_p.h b/src/qml/jsruntime/qv4regexp_p.h
index 8a178dd2f6..89f9515917 100644
--- a/src/qml/jsruntime/qv4regexp_p.h
+++ b/src/qml/jsruntime/qv4regexp_p.h
@@ -14,21 +14,18 @@
// We mean it.
//
-#include <QString>
-#include <QVector>
-
-#include <wtf/RefPtr.h>
-#include <wtf/FastAllocBase.h>
-#include <wtf/BumpPointerAllocator.h>
-
-#include <limits.h>
+// Yarr.h is not self-contained. Make sure it sees uint8_t
+#include <cstdint>
#include <yarr/Yarr.h>
#include <yarr/YarrInterpreter.h>
#include <yarr/YarrJIT.h>
-#include "qv4managed_p.h"
-#include "qv4engine_p.h"
+#include <private/qv4compileddata_p.h>
+#include <private/qv4managed_p.h>
+
+#include <QtCore/qstring.h>
+#include <QtCore/qvector.h>
QT_BEGIN_NAMESPACE
@@ -64,12 +61,16 @@ struct RegExp : Base {
RegExpCache *cache;
int subPatternCount;
- uint flags;
- bool valid;
+
+#if ENABLE(YARR_JIT)
+ bool isJittable() const { return !jitFailed; }
+ int interpreterCallCount;
bool jitFailed;
- quint8 matchCount;
+#endif
+
+ quint8 flags;
+ bool valid;
- QString flagsAsString() const;
int captureCount() const { return subPatternCount + 1; }
};
Q_STATIC_ASSERT(std::is_trivial_v<RegExp>);
@@ -96,7 +97,9 @@ struct RegExp : public Managed
bool unicode() const { return d()->unicode(); }
bool sticky() const { return d()->sticky(); }
- static Heap::RegExp *create(ExecutionEngine* engine, const QString& pattern, uint flags = CompiledData::RegExp::RegExp_NoFlags);
+ static Heap::RegExp *create(
+ ExecutionEngine *engine, const QString &pattern,
+ CompiledData::RegExp::Flags flags = CompiledData::RegExp::RegExp_NoFlags);
bool isValid() const { return d()->valid; }
@@ -122,7 +125,7 @@ struct RegExpCacheKey
{ return !operator==(other); }
QString pattern;
- uint flags;
+ quint8 flags;
};
inline RegExpCacheKey::RegExpCacheKey(const RegExp::Data *re)
@@ -131,7 +134,7 @@ inline RegExpCacheKey::RegExpCacheKey(const RegExp::Data *re)
{}
inline size_t qHash(const RegExpCacheKey& key, size_t seed = 0) noexcept
-{ return qHash(key.pattern, seed); }
+{ return qHashMulti(seed, key.pattern, key.flags); }
class RegExpCache : public QHash<RegExpCacheKey, WeakValue>
{