From 96f9151e4a835fb5440faa0846a8eb510ee58e22 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 2 May 2025 22:07:37 +0200 Subject: [PATCH] QStyleSheetStyle: avoid creating QString Don't create a QString when comparing the strings from knownPseudoElements - a QLatin1StringView is enough. Change-Id: I69e207bac0fb3d3df12ae9d4bebc9cd30cde30de Reviewed-by: Volker Hilsheimer Reviewed-by: Axel Spoerl (cherry picked from commit 15c2ec5344fb8a1e5d4a8e93d410c54563fb86b4) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit fe777849c95ca66bdfe29e65016669e349909e49) --- src/widgets/styles/qstylesheetstyle.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index bedf11b1b6f..d735a13abaf 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -247,7 +247,7 @@ struct PseudoElementInfo { const char name[19]; }; -static const PseudoElementInfo knownPseudoElements[NumPseudoElements] = { +static constexpr PseudoElementInfo knownPseudoElements[NumPseudoElements] = { { QStyle::SC_None, "" }, { QStyle::SC_None, "down-arrow" }, { QStyle::SC_None, "up-arrow" }, @@ -300,7 +300,7 @@ static const PseudoElementInfo knownPseudoElements[NumPseudoElements] = { { QStyle::SC_SliderGroove, "groove" }, { QStyle::SC_SliderHandle, "handle" }, { QStyle::SC_None, "add-page" }, - { QStyle::SC_None, "sub-page"}, + { QStyle::SC_None, "sub-page" }, { QStyle::SC_SliderTickmarks, "tick-mark" }, { QStyle::SC_None, "pane" }, { QStyle::SC_None, "tab-bar" }, @@ -1749,7 +1749,7 @@ QList QStyleSheetStyle::styleRules(const QObject *obj) const ///////////////////////////////////////////////////////////////////////////////////////// // Rendering rules -static QList declarations(const QList &styleRules, const QString &part, +static QList declarations(const QList &styleRules, QLatin1StringView part, quint64 pseudoClass = PseudoClass_Unspecified) { QList decls; @@ -1898,7 +1898,7 @@ QRenderRule QStyleSheetStyle::renderRule(const QObject *obj, int element, quint6 } - const QString part = QLatin1StringView(knownPseudoElements[element].name); + const auto part = QLatin1StringView(knownPseudoElements[element].name); QList decls = declarations(rules, part, state); QRenderRule newRule(decls, obj); cache[state] = newRule; @@ -2204,7 +2204,7 @@ bool QStyleSheetStyle::hasStyleRule(const QObject *obj, int part) const return result; } - auto pseudoElement = QLatin1StringView(knownPseudoElements[part].name); + const auto pseudoElement = QLatin1StringView(knownPseudoElements[part].name); for (int i = 0; i < rules.size(); i++) { const Selector& selector = rules.at(i).selectors.at(0); if (pseudoElement.compare(selector.pseudoElement(), Qt::CaseInsensitive) == 0) { @@ -2671,7 +2671,7 @@ void QStyleSheetStyle::setProperties(QWidget *w) // Set value for each property in the order of property final occurrence // since properties interact. - const QList decls = declarations(styleRules(w), QString()); + const QList decls = declarations(styleRules(w), {}); QList finals; // indices in reverse order of each property's final occurrence {