From b739b3a0402e71041d99fa138630b806059b19b2 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 24 Dec 2017 14:13:39 +0100 Subject: QSqlRecord: (re)speedup indexOf(const QString& name) While adding the possibility to access values for QSqlRecord with decorated field names (table.field), some string-allocations were added which created a remarkable slowdown. Replace the QString allocations with QStringRef avoids those allocations and restores the speed for normal operations (apart from on QString::indexOf() call and some integer comparisons) Task-number: QTBUG-65226 Change-Id: I9e458523891421abce9e4a7ed931fec000dcbe76 Reviewed-by: Andy Shaw --- src/sql/kernel/qsqlrecord.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/sql/kernel/qsqlrecord.cpp') diff --git a/src/sql/kernel/qsqlrecord.cpp b/src/sql/kernel/qsqlrecord.cpp index 1c9ad5ec63..ecbe3eacdb 100644 --- a/src/sql/kernel/qsqlrecord.cpp +++ b/src/sql/kernel/qsqlrecord.cpp @@ -232,18 +232,19 @@ QString QSqlRecord::fieldName(int index) const int QSqlRecord::indexOf(const QString& name) const { - QString tableName; - QString fieldName = name; + QStringRef tableName; + QStringRef fieldName(&name); const int idx = name.indexOf(QLatin1Char('.')); if (idx != -1) { - tableName = name.left(idx); - fieldName = name.mid(idx + 1); + tableName = name.leftRef(idx); + fieldName = name.midRef(idx + 1); } - for (int i = 0; i < count(); ++i) { + const int cnt = count(); + for (int i = 0; i < cnt; ++i) { // Check the passed in name first in case it is an alias using a dot. // Then check if both the table and field match when there is a table name specified. - const auto currentField = d->fields.at(i); - const auto currentFieldName = currentField.name(); + const auto ¤tField = d->fields.at(i); + const auto ¤tFieldName = currentField.name(); if (currentFieldName.compare(name, Qt::CaseInsensitive) == 0 || (idx != -1 && currentFieldName.compare(fieldName, Qt::CaseInsensitive) == 0 && currentField.tableName().compare(tableName, Qt::CaseInsensitive) == 0)) { -- cgit v1.2.3