summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2025-08-18 15:03:38 +0200
committerQt Cherry-pick Bot <[email protected]>2025-08-20 05:46:43 +0000
commit0945156dc262d6818a4b41e155babbf6ad3e7087 (patch)
tree997a0adf5ff3103c1a71dce900ab997c133fe4f3 /src
parent3a545d75886685ac5b4195ea8e985120972b8468 (diff)
QString: further optimize the invalid regex warning6.9
Error handling code has no business bloating Qt executable code size, so take two more steps to reduce its impact, on top of the locking it away in a Q_DECL_COLD_FUNCTION: First, split the 'where' argument into 'class' and 'method', in order to facilitate the reuse of the class strings across users. Second, move the QRegularExpression::pattern() call into the warning function, to centralize the temporary QString handling code. Saves half a KiB in text size on optimized Clang 19 Linux AMD64 C++23 builds. Pick-to: 6.8 Change-Id: I7fe23bdafc9f63d0d43b801e704866be9961648c Reviewed-by: Thiago Macieira <[email protected]> (cherry picked from commit c1a4f722eca79a1811304a47349d332d57a86704) Reviewed-by: Qt Cherry-pick Bot <[email protected]> (cherry picked from commit a9222a900d718ecdbf9d88485ceeb9f871e2c331)
Diffstat (limited to 'src')
-rw-r--r--src/corelib/text/qregularexpression.cpp11
-rw-r--r--src/corelib/text/qstring.cpp20
2 files changed, 18 insertions, 13 deletions
diff --git a/src/corelib/text/qregularexpression.cpp b/src/corelib/text/qregularexpression.cpp
index a8ff90b5072..061f2bfa0e3 100644
--- a/src/corelib/text/qregularexpression.cpp
+++ b/src/corelib/text/qregularexpression.cpp
@@ -800,13 +800,14 @@ struct QRegularExpressionMatchIteratorPrivate : QSharedData
(pass it to qUtf16Printable, etc.), so we need to check for that.
*/
Q_DECL_COLD_FUNCTION
-void qtWarnAboutInvalidRegularExpression(const QString &pattern, const char *where)
+void qtWarnAboutInvalidRegularExpression(const QString &pattern, const char *cls, const char *method)
{
if (pattern.isValidUtf16()) {
- qWarning("%s(): called on an invalid QRegularExpression object "
- "(pattern is '%ls')", where, qUtf16Printable(pattern));
+ qWarning("%s::%s(): called on an invalid QRegularExpression object "
+ "(pattern is '%ls')", cls, method, qUtf16Printable(pattern));
} else {
- qWarning("%s(): called on an invalid QRegularExpression object", where);
+ qWarning("%s::%s(): called on an invalid QRegularExpression object",
+ cls, method);
}
}
@@ -1118,7 +1119,7 @@ void QRegularExpressionPrivate::doMatch(QRegularExpressionMatchPrivate *priv,
return;
if (Q_UNLIKELY(!compiledPattern)) {
- qtWarnAboutInvalidRegularExpression(pattern, "QRegularExpressionPrivate::doMatch");
+ qtWarnAboutInvalidRegularExpression(pattern, "QRegularExpressionPrivate", "doMatch");
return;
}
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index a72abadcd0f..5d82ddf1e4a 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -1637,7 +1637,11 @@ static int qArgDigitValue(QChar ch) noexcept
#if QT_CONFIG(regularexpression)
Q_DECL_COLD_FUNCTION
-void qtWarnAboutInvalidRegularExpression(const QString &pattern, const char *where);
+static void qtWarnAboutInvalidRegularExpression(const QRegularExpression &re, const char *cls, const char *method)
+{
+ extern void qtWarnAboutInvalidRegularExpression(const QString &pattern, const char *cls, const char *method);
+ qtWarnAboutInvalidRegularExpression(re.pattern(), cls, method);
+}
#endif
/*!
@@ -4721,7 +4725,7 @@ Q_DECLARE_TYPEINFO(QStringCapture, Q_PRIMITIVE_TYPE);
QString &QString::replace(const QRegularExpression &re, const QString &after)
{
if (!re.isValid()) {
- qtWarnAboutInvalidRegularExpression(re.pattern(), "QString::replace");
+ qtWarnAboutInvalidRegularExpression(re, "QString", "replace");
return *this;
}
@@ -5241,7 +5245,7 @@ static QString extractSections(QSpan<qt_section_chunk> sections, qsizetype start
QString QString::section(const QRegularExpression &re, qsizetype start, qsizetype end, SectionFlags flags) const
{
if (!re.isValid()) {
- qtWarnAboutInvalidRegularExpression(re.pattern(), "QString::section");
+ qtWarnAboutInvalidRegularExpression(re, "QString", "section");
return QString();
}
@@ -8341,7 +8345,7 @@ static ResultList splitString(const String &source, const QRegularExpression &re
{
ResultList list;
if (!re.isValid()) {
- qtWarnAboutInvalidRegularExpression(re.pattern(), "QString::split");
+ qtWarnAboutInvalidRegularExpression(re, "QString", "split");
return list;
}
@@ -9971,7 +9975,7 @@ qsizetype QtPrivate::lastIndexOf(QLatin1StringView haystack, qsizetype from, QLa
qsizetype QtPrivate::indexOf(QStringView viewHaystack, const QString *stringHaystack, const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
{
if (!re.isValid()) {
- qtWarnAboutInvalidRegularExpression(re.pattern(), "QString(View)::indexOf");
+ qtWarnAboutInvalidRegularExpression(re, "QString(View)", "indexOf");
return -1;
}
@@ -9996,7 +10000,7 @@ qsizetype QtPrivate::indexOf(QStringView haystack, const QRegularExpression &re,
qsizetype QtPrivate::lastIndexOf(QStringView viewHaystack, const QString *stringHaystack, const QRegularExpression &re, qsizetype from, QRegularExpressionMatch *rmatch)
{
if (!re.isValid()) {
- qtWarnAboutInvalidRegularExpression(re.pattern(), "QString(View)::lastIndexOf");
+ qtWarnAboutInvalidRegularExpression(re, "QString(View)", "lastIndexOf");
return -1;
}
@@ -10028,7 +10032,7 @@ qsizetype QtPrivate::lastIndexOf(QStringView haystack, const QRegularExpression
bool QtPrivate::contains(QStringView viewHaystack, const QString *stringHaystack, const QRegularExpression &re, QRegularExpressionMatch *rmatch)
{
if (!re.isValid()) {
- qtWarnAboutInvalidRegularExpression(re.pattern(), "QString(View)::contains");
+ qtWarnAboutInvalidRegularExpression(re, "QString(View)", "contains");
return false;
}
QRegularExpressionMatch m = stringHaystack
@@ -10048,7 +10052,7 @@ bool QtPrivate::contains(QStringView haystack, const QRegularExpression &re, QRe
qsizetype QtPrivate::count(QStringView haystack, const QRegularExpression &re)
{
if (!re.isValid()) {
- qtWarnAboutInvalidRegularExpression(re.pattern(), "QString(View)::count");
+ qtWarnAboutInvalidRegularExpression(re, "QString(View)", "count");
return 0;
}
qsizetype count = 0;