summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <[email protected]>2025-03-17 16:00:43 +0100
committerQt Cherry-pick Bot <[email protected]>2025-03-21 08:59:28 +0000
commitd35391ae2d4abe8e8e6a8458e115dd325e7cd852 (patch)
treeec130144060203f23057aa9403db74cb5bff39d6
parent72d537716fc9a397959b83828bc8bd6fa3cff4dd (diff)
QSqlQueryModel: memoize roleNames()
The return value of this function is constant and some users (QML?) may call this function often, so memoize the result of the function instead of re-creating the QHash on every call. Amends 40206a9f6d7635bb19305d1c8d74908808e3529e. Not picking to Qt 5, because I'm unsure about the state of magic statics there, and I don't want to take out the Q_GLOBAL_STATIC sledgehammer. Pick-to: 6.5 Change-Id: I8311e93ea16982c82e8312e1e104d95ed062fe6b Reviewed-by: Edward Welbourne <[email protected]> (cherry picked from commit 0d0a151e0d3a93bcd289751b56959a7655a049d2) Reviewed-by: Qt Cherry-pick Bot <[email protected]> (cherry picked from commit dd1349240f4172a38160e203fe18850eb8871efb)
-rw-r--r--src/sql/models/qsqlquerymodel.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/sql/models/qsqlquerymodel.cpp b/src/sql/models/qsqlquerymodel.cpp
index f109f042f16..b50a23a7961 100644
--- a/src/sql/models/qsqlquerymodel.cpp
+++ b/src/sql/models/qsqlquerymodel.cpp
@@ -193,9 +193,10 @@ bool QSqlQueryModel::canFetchMore(const QModelIndex &parent) const
*/
QHash<int, QByteArray> QSqlQueryModel::roleNames() const
{
- return QHash<int, QByteArray> {
+ static const QHash<int, QByteArray> names = {
{ Qt::DisplayRole, QByteArrayLiteral("display") }
};
+ return names;
}
/*! \internal