QSqlResult: use QVector<int> instead QList<int> for indexes value
Minor tweak: QList<int> is taking 64bit per entry, QVector<int> only 32bit - this should reduce memory usage a little bit. Change-Id: I3e17269feb4840343f5cecfc71f8fccd70edc80f Reviewed-by: Andy Shaw <andy.shaw@qt.io>
This commit is contained in:
parent
25956a1e7c
commit
69948f4899
@ -471,7 +471,7 @@ bool QSQLiteResult::exec()
|
||||
// can end up in a case where for virtual tables it returns 0 even though it
|
||||
// has parameters
|
||||
if (paramCount > 1 && paramCount < values.count()) {
|
||||
const auto countIndexes = [](int counter, const QList<int>& indexList) {
|
||||
const auto countIndexes = [](int counter, const QVector<int> &indexList) {
|
||||
return counter + indexList.length();
|
||||
};
|
||||
|
||||
@ -485,13 +485,14 @@ bool QSQLiteResult::exec()
|
||||
// placeholders. So we need to ensure the QVector has only one instance of
|
||||
// each value as SQLite will do the rest for us.
|
||||
QVector<QVariant> prunedValues;
|
||||
QList<int> handledIndexes;
|
||||
QVector<int> handledIndexes;
|
||||
for (int i = 0, currentIndex = 0; i < values.size(); ++i) {
|
||||
if (handledIndexes.contains(i))
|
||||
continue;
|
||||
const auto placeHolder = QString::fromUtf8(sqlite3_bind_parameter_name(d->stmt, currentIndex + 1));
|
||||
handledIndexes << d->indexes[placeHolder];
|
||||
prunedValues << values.at(d->indexes[placeHolder].first());
|
||||
const auto &indexes = d->indexes.value(placeHolder);
|
||||
handledIndexes << indexes;
|
||||
prunedValues << values.at(indexes.first());
|
||||
++currentIndex;
|
||||
}
|
||||
values = prunedValues;
|
||||
|
@ -690,7 +690,7 @@ void QSqlResult::bindValue(int index, const QVariant& val, QSql::ParamType param
|
||||
{
|
||||
Q_D(QSqlResult);
|
||||
d->binds = PositionalBinding;
|
||||
QList<int>& indexes = d->indexes[d->fieldSerial(index)];
|
||||
QVector<int> &indexes = d->indexes[d->fieldSerial(index)];
|
||||
if (!indexes.contains(index))
|
||||
indexes.append(index);
|
||||
if (d->values.count() <= index)
|
||||
@ -717,7 +717,7 @@ void QSqlResult::bindValue(const QString& placeholder, const QVariant& val,
|
||||
d->binds = NamedBinding;
|
||||
// if the index has already been set when doing emulated named
|
||||
// bindings - don't reset it
|
||||
const QList<int> indexes = d->indexes.value(placeholder);
|
||||
const QVector<int> indexes = d->indexes.value(placeholder);
|
||||
for (int idx : indexes) {
|
||||
if (d->values.count() <= idx)
|
||||
d->values.resize(idx + 1);
|
||||
@ -764,7 +764,7 @@ QVariant QSqlResult::boundValue(int index) const
|
||||
QVariant QSqlResult::boundValue(const QString& placeholder) const
|
||||
{
|
||||
Q_D(const QSqlResult);
|
||||
QList<int> indexes = d->indexes.value(placeholder);
|
||||
const QVector<int> indexes = d->indexes.value(placeholder);
|
||||
return d->values.value(indexes.value(0,-1));
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,7 @@ public:
|
||||
QString executedQuery;
|
||||
QHash<int, QSql::ParamType> types;
|
||||
QVector<QVariant> values;
|
||||
typedef QHash<QString, QList<int> > IndexMap;
|
||||
typedef QHash<QString, QVector<int> > IndexMap;
|
||||
IndexMap indexes;
|
||||
|
||||
typedef QVector<QHolder> QHolderVector;
|
||||
|
Loading…
x
Reference in New Issue
Block a user