Reduce allocations in QSQLiteDriver::open()'s connection options parsing

- Use splitRef() instead of split(), avoiding small temporary
  QStrings.
- Don't remove all spaces before splitting, trim strings at
  the QStringRef level later, where needed. This will reject
  nonsense strings like QSQL_ LITE _BUSY_ TI MEOUT= 1 2 3 that
  were previously (wrongly) accepted.
- Use C++11 range-for loop.

Change-Id: I875c4cf47b7a283ba55783f70c903bb9947e1cd7
Reviewed-by: Mark Brand <mabrand@mabrand.nl>
bb10
Marc Mutz 2016-02-15 13:42:51 +01:00
parent c7c7cf636b
commit a93ff2c248
1 changed files with 11 additions and 7 deletions

View File

@ -613,13 +613,17 @@ bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, c
bool openReadOnlyOption = false;
bool openUriOption = false;
const QStringList opts = QString(conOpts).remove(QLatin1Char(' ')).split(QLatin1Char(';'));
foreach (const QString &option, opts) {
if (option.startsWith(QLatin1String("QSQLITE_BUSY_TIMEOUT="))) {
bool ok;
const int nt = option.midRef(21).toInt(&ok);
if (ok)
timeOut = nt;
const auto opts = conOpts.splitRef(QLatin1Char(';'));
for (auto option : opts) {
option = option.trimmed();
if (option.startsWith(QLatin1String("QSQLITE_BUSY_TIMEOUT"))) {
option = option.mid(20).trimmed();
if (option.startsWith(QLatin1Char('='))) {
bool ok;
const int nt = option.mid(1).trimmed().toInt(&ok);
if (ok)
timeOut = nt;
}
} else if (option == QLatin1String("QSQLITE_OPEN_READONLY")) {
openReadOnlyOption = true;
} else if (option == QLatin1String("QSQLITE_OPEN_URI")) {