diff options
author | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2010-02-16 18:23:18 +0100 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@nokia.com> | 2010-02-16 19:10:38 +0100 |
commit | d590fc729e3afaedf181da58f8b685d7597040da (patch) | |
tree | 446692610d5d85733074042115118a556f39c0e3 /src/sql/drivers | |
parent | e6b629f3ebc1d530218f01a735275e56bf474a18 (diff) | |
download | qt4-tools-d590fc729e3afaedf181da58f8b685d7597040da.tar.gz |
optimization: get rid of QString::fromUtf16() usage, part 2
QString::fromUtf16() is slow - it does a BOM check and optionally byte
swapping, which is utterly irrelevant when converting internal data
structures which are raw utf16 in host byte order. so replace it with
QString::fromUnicode() where possible (which seems to be everywhere).
the reasoning is the same as in commit e0fda52f, so not getting further
reviews.
Reviewed-by: denis
Reviewed-by: joao
Diffstat (limited to 'src/sql/drivers')
-rw-r--r-- | src/sql/drivers/db2/qsql_db2.cpp | 4 | ||||
-rw-r--r-- | src/sql/drivers/oci/qsql_oci.cpp | 15 | ||||
-rw-r--r-- | src/sql/drivers/odbc/qsql_odbc.cpp | 2 | ||||
-rw-r--r-- | src/sql/drivers/sqlite/qsql_sqlite.cpp | 10 |
4 files changed, 15 insertions, 16 deletions
diff --git a/src/sql/drivers/db2/qsql_db2.cpp b/src/sql/drivers/db2/qsql_db2.cpp index d5b398429d..ea0b42e0d7 100644 --- a/src/sql/drivers/db2/qsql_db2.cpp +++ b/src/sql/drivers/db2/qsql_db2.cpp @@ -109,7 +109,7 @@ public: static QString qFromTChar(SQLTCHAR* str) { - return QString::fromUtf16(str); + return QString((const QChar *)str); } // dangerous!! (but fast). Don't use in functions that @@ -833,7 +833,7 @@ bool QDB2Result::exec() break; case QVariant::String: if (bindValueType(i) & QSql::Out) - values[i] = QString::fromUtf16((ushort*)tmpStorage.takeFirst().constData()); + values[i] = QString((const QChar *)tmpStorage.takeFirst().constData()); break; default: { values[i] = QString::fromAscii(tmpStorage.takeFirst().constData()); diff --git a/src/sql/drivers/oci/qsql_oci.cpp b/src/sql/drivers/oci/qsql_oci.cpp index 01c4124c9f..b5c85e696b 100644 --- a/src/sql/drivers/oci/qsql_oci.cpp +++ b/src/sql/drivers/oci/qsql_oci.cpp @@ -364,8 +364,8 @@ static void qOraOutValue(QVariant &value, QList<QByteArray> &storage) value = qMakeDate(storage.takeFirst()); break; case QVariant::String: - value = QString::fromUtf16( - reinterpret_cast<const ushort *>(storage.takeFirst().constData())); + value = QString( + reinterpret_cast<const QChar *>(storage.takeFirst().constData())); break; default: break; //nothing @@ -454,7 +454,7 @@ QString qOraWarn(OCIError *err, int *errorCode) OCI_HTYPE_ERROR); if (errorCode) *errorCode = errcode; - return QString::fromUtf16(reinterpret_cast<const ushort *>(errbuf)); + return QString(reinterpret_cast<const QChar *>(errbuf)); } void qOraWarning(const char* msg, OCIError *err) @@ -989,8 +989,7 @@ int QOCICols::readPiecewise(QVector<QVariant> &values, int index) } else { if (isStringField) { QString str = values.at(fieldNum + index).toString(); - str += QString::fromUtf16(reinterpret_cast<const ushort *>(col), - chunkSize / 2); + str += QString(reinterpret_cast<const QChar *>(col), chunkSize / 2); values[fieldNum + index] = str; fieldInf[fieldNum].ind = 0; } else { @@ -1457,7 +1456,7 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVector<QVariant> &boundValues, b break; case SQLT_STR: - (*list)[r] = QString::fromUtf16(reinterpret_cast<ushort *>(data + (*list)[r] = QString(reinterpret_cast<const QChar *>(data + r * columns[i].maxLen)); break; @@ -1608,7 +1607,7 @@ void QOCICols::getValues(QVector<QVariant> &v, int index) } // else fall through case QVariant::String: - v[index + i] = QString::fromUtf16(reinterpret_cast<const ushort *>(fld.data)); + v[index + i] = QString(reinterpret_cast<const QChar *>(fld.data)); break; case QVariant::ByteArray: if (fld.len > 0) @@ -2102,7 +2101,7 @@ bool QOCIDriver::open(const QString & db, qWarning("QOCIDriver::open: could not get Oracle server version."); } else { QString versionStr; - versionStr = QString::fromUtf16(reinterpret_cast<ushort *>(vertxt)); + versionStr = QString(reinterpret_cast<const QChar *>(vertxt)); QRegExp vers(QLatin1String("([0-9]+)\\.[0-9\\.]+[0-9]")); if (vers.indexIn(versionStr) >= 0) d->serverVersion = vers.cap(1).toInt(); diff --git a/src/sql/drivers/odbc/qsql_odbc.cpp b/src/sql/drivers/odbc/qsql_odbc.cpp index 18bc743670..fab3ab3c2b 100644 --- a/src/sql/drivers/odbc/qsql_odbc.cpp +++ b/src/sql/drivers/odbc/qsql_odbc.cpp @@ -1558,7 +1558,7 @@ bool QODBCResult::exec() case QVariant::String: if (d->unicode) { if (bindValueType(i) & QSql::Out) - values[i] = QString::fromUtf16((ushort*)tmpStorage.takeFirst().constData()); + values[i] = QString((QChar *)tmpStorage.takeFirst().constData()); break; } // fall through diff --git a/src/sql/drivers/sqlite/qsql_sqlite.cpp b/src/sql/drivers/sqlite/qsql_sqlite.cpp index d3be304b02..24dcad9f18 100644 --- a/src/sql/drivers/sqlite/qsql_sqlite.cpp +++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp @@ -95,7 +95,7 @@ static QSqlError qMakeError(sqlite3 *access, const QString &descr, QSqlError::Er int errorCode = -1) { return QSqlError(descr, - QString::fromUtf16(static_cast<const ushort *>(sqlite3_errmsg16(access))), + QString(reinterpret_cast<const QChar *>(sqlite3_errmsg16(access))), type, errorCode); } @@ -162,13 +162,13 @@ void QSQLiteResultPrivate::initColumns(bool emptyResultset) q->init(nCols); for (int i = 0; i < nCols; ++i) { - QString colName = QString::fromUtf16( - static_cast<const ushort *>(sqlite3_column_name16(stmt, i)) + QString colName = QString(reinterpret_cast<const QChar *>( + sqlite3_column_name16(stmt, i)) ).remove(QLatin1Char('"')); // must use typeName for resolving the type to match QSqliteDriver::record - QString typeName = QString::fromUtf16( - static_cast<const ushort *>(sqlite3_column_decltype16(stmt, i))); + QString typeName = QString(reinterpret_cast<const QChar *>( + sqlite3_column_decltype16(stmt, i))); int dotIdx = colName.lastIndexOf(QLatin1Char('.')); QSqlField fld(colName.mid(dotIdx == -1 ? 0 : dotIdx + 1), qGetColumnType(typeName)); |