QSqlTableModel: avoid extra QMap lookup
authorMark Brand <mabrand@mabrand.nl>
Wed, 15 Feb 2012 09:22:15 +0000 (10:22 +0100)
committerQt by Nokia <qt-info@nokia.com>
Thu, 23 Feb 2012 22:42:59 +0000 (23:42 +0100)
The consensus on #qt-labs seems to be that there is little or no
point in checking with contains() before using value(), even if
the map does not contain the key in most cases.

Change-Id: I34740a91d5c3af65e20937a5ae3b4bab32406440
Reviewed-by: Robin Burchell <robin+qt@viroteck.net>
src/sql/models/qsqltablemodel.cpp

index f30352e..0cb7c39 100644 (file)
@@ -439,13 +439,11 @@ QVariant QSqlTableModel::headerData(int section, Qt::Orientation orientation, in
 {
     Q_D(const QSqlTableModel);
     if (orientation == Qt::Vertical && role == Qt::DisplayRole) {
-        if (d->cache.contains(section)) {
-            const QSqlTableModelPrivate::Op op = d->cache.value(section).op();
-            if (op == QSqlTableModelPrivate::Insert)
-                return QLatin1String("*");
-            else if (op == QSqlTableModelPrivate::Delete)
-                return QLatin1String("!");
-        }
+        const QSqlTableModelPrivate::Op op = d->cache.value(section).op();
+        if (op == QSqlTableModelPrivate::Insert)
+            return QLatin1String("*");
+        else if (op == QSqlTableModelPrivate::Delete)
+            return QLatin1String("!");
     }
     return QSqlQueryModel::headerData(section, orientation, role);
 }