aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Spoerl <axel.spoerl@qt.io>2024-04-25 07:24:23 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-04-25 10:42:24 +0000
commitfb724d5919eaf64bfddcb9aa19fabde951517c45 (patch)
tree5a2addbc6c642767488e494079d7ff1533f22cb5
parent5b39edf755e3224950918ad8b1a6ca0d0801a255 (diff)
TableModelRow QML Type: Optimize data role strings
String accessors used for data roles in a TableModelRow were defined as static const QString members. supportedRoleNames() returned a hash, built on each call. String definitions corresponding to data roles were defined another time in this method. Define accessor strings as static constexpr QLatin1StringView. Use these members in supportedRoleNames(), instead of defining the same strings another time. Define the hash as static const, instead of building it on each call. Pick-to: 6.6 Change-Id: I38752fda85e54b0e9107c31ec8f32c6886b97b90 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> (cherry picked from commit 330fa93d6e9003c0ea188b9e703f2b3f0448f8c8) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/labs/models/qqmltablemodelcolumn.cpp59
1 files changed, 30 insertions, 29 deletions
diff --git a/src/labs/models/qqmltablemodelcolumn.cpp b/src/labs/models/qqmltablemodelcolumn.cpp
index 9f94e241b2..356cad476f 100644
--- a/src/labs/models/qqmltablemodelcolumn.cpp
+++ b/src/labs/models/qqmltablemodelcolumn.cpp
@@ -45,23 +45,23 @@ QT_BEGIN_NAMESPACE
\sa TableModel, TableView
*/
-static const QString displayRoleName = QStringLiteral("display");
-static const QString decorationRoleName = QStringLiteral("decoration");
-static const QString editRoleName = QStringLiteral("edit");
-static const QString toolTipRoleName = QStringLiteral("toolTip");
-static const QString statusTipRoleName = QStringLiteral("statusTip");
-static const QString whatsThisRoleName = QStringLiteral("whatsThis");
+static constexpr QLatin1StringView displayRoleName("display");
+static constexpr QLatin1StringView decorationRoleName("decoration");
+static constexpr QLatin1StringView editRoleName("edit");
+static constexpr QLatin1StringView toolTipRoleName("toolTip");
+static constexpr QLatin1StringView statusTipRoleName("statusTip");
+static constexpr QLatin1StringView whatsThisRoleName("whatsThis");
-static const QString fontRoleName = QStringLiteral("font");
-static const QString textAlignmentRoleName = QStringLiteral("textAlignment");
-static const QString backgroundRoleName = QStringLiteral("background");
-static const QString foregroundRoleName = QStringLiteral("foreground");
-static const QString checkStateRoleName = QStringLiteral("checkState");
+static constexpr QLatin1StringView fontRoleName("font");
+static constexpr QLatin1StringView textAlignmentRoleName("textAlignment");
+static constexpr QLatin1StringView backgroundRoleName("background");
+static constexpr QLatin1StringView foregroundRoleName("foreground");
+static constexpr QLatin1StringView checkStateRoleName("checkState");
-static const QString accessibleTextRoleName = QStringLiteral("accessibleText");
-static const QString accessibleDescriptionRoleName = QStringLiteral("accessibleDescription");
+static constexpr QLatin1StringView accessibleTextRoleName("accessibleText");
+static constexpr QLatin1StringView accessibleDescriptionRoleName("accessibleDescription");
-static const QString sizeHintRoleName = QStringLiteral("sizeHint");
+static constexpr QLatin1StringView sizeHintRoleName("sizeHint");
QQmlTableModelColumn::QQmlTableModelColumn(QObject *parent)
@@ -166,21 +166,22 @@ const QHash<QString, QJSValue> QQmlTableModelColumn::getters() const
const QHash<int, QString> QQmlTableModelColumn::supportedRoleNames()
{
- QHash<int, QString> names;
- names[Qt::DisplayRole] = QLatin1String("display");
- names[Qt::DecorationRole] = QLatin1String("decoration");
- names[Qt::EditRole] = QLatin1String("edit");
- names[Qt::ToolTipRole] = QLatin1String("toolTip");
- names[Qt::StatusTipRole] = QLatin1String("statusTip");
- names[Qt::WhatsThisRole] = QLatin1String("whatsThis");
- names[Qt::FontRole] = QLatin1String("font");
- names[Qt::TextAlignmentRole] = QLatin1String("textAlignment");
- names[Qt::BackgroundRole] = QLatin1String("background");
- names[Qt::ForegroundRole] = QLatin1String("foreground");
- names[Qt::CheckStateRole] = QLatin1String("checkState");
- names[Qt::AccessibleTextRole] = QLatin1String("accessibleText");
- names[Qt::AccessibleDescriptionRole] = QLatin1String("accessibleDescription");
- names[Qt::SizeHintRole] = QLatin1String("sizeHint");
+ static const QHash<int, QString> names {
+ {Qt::DisplayRole, displayRoleName},
+ {Qt::DecorationRole, decorationRoleName},
+ {Qt::EditRole, editRoleName},
+ {Qt::ToolTipRole, toolTipRoleName},
+ {Qt::StatusTipRole, statusTipRoleName},
+ {Qt::WhatsThisRole, whatsThisRoleName},
+ {Qt::FontRole, fontRoleName},
+ {Qt::TextAlignmentRole, textAlignmentRoleName},
+ {Qt::BackgroundRole, backgroundRoleName},
+ {Qt::ForegroundRole, foregroundRoleName},
+ {Qt::CheckStateRole, checkStateRoleName},
+ {Qt::AccessibleTextRole, accessibleTextRoleName},
+ {Qt::AccessibleDescriptionRole, accessibleDescriptionRoleName},
+ {Qt::SizeHintRole, sizeHintRoleName}
+ };
return names;
}