summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2017-12-24 14:13:39 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-01-06 05:17:28 +0000
commitb739b3a0402e71041d99fa138630b806059b19b2 (patch)
treea5794029ee5051880b35f06604e4341d5e3f2b94
parent1e75dcf2518e37a7b83d006a4e002f972615b43b (diff)
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 <andy.shaw@qt.io>
-rw-r--r--src/sql/kernel/qsqlrecord.cpp15
1 files changed, 8 insertions, 7 deletions
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 &currentField = d->fields.at(i);
+ const auto &currentFieldName = currentField.name();
if (currentFieldName.compare(name, Qt::CaseInsensitive) == 0
|| (idx != -1 && currentFieldName.compare(fieldName, Qt::CaseInsensitive) == 0
&& currentField.tableName().compare(tableName, Qt::CaseInsensitive) == 0)) {