From d590fc729e3afaedf181da58f8b685d7597040da Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 16 Feb 2010 18:23:18 +0100 Subject: 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 --- src/3rdparty/phonon/ds9/mediagraph.cpp | 12 ++++++------ src/3rdparty/phonon/waveout/mediaobject.cpp | 2 +- src/corelib/io/qprocess_symbian.cpp | 2 +- src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp | 8 ++++---- src/multimedia/audio/qaudioinput_win32_p.cpp | 2 +- src/multimedia/audio/qaudiooutput_win32_p.cpp | 2 +- src/sql/drivers/db2/qsql_db2.cpp | 4 ++-- src/sql/drivers/oci/qsql_oci.cpp | 15 +++++++-------- src/sql/drivers/odbc/qsql_odbc.cpp | 2 +- src/sql/drivers/sqlite/qsql_sqlite.cpp | 10 +++++----- 10 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/3rdparty/phonon/ds9/mediagraph.cpp b/src/3rdparty/phonon/ds9/mediagraph.cpp index a467dd7..3e7a68b 100644 --- a/src/3rdparty/phonon/ds9/mediagraph.cpp +++ b/src/3rdparty/phonon/ds9/mediagraph.cpp @@ -379,7 +379,7 @@ namespace Phonon FILTER_INFO info; filter->QueryFilterInfo(&info); #ifdef GRAPH_DEBUG - qDebug() << "removeFilter" << QString::fromUtf16(info.achName); + qDebug() << "removeFilter" << QString((const QChar *)info.achName); #endif if (info.pGraph) { info.pGraph->Release(); @@ -875,7 +875,7 @@ namespace Phonon { FILTER_INFO info; filter->QueryFilterInfo(&info); - qDebug() << Q_FUNC_INFO << QString::fromUtf16(info.achName); + qDebug() << Q_FUNC_INFO << QString((const QChar *)info.achName); if (info.pGraph) { info.pGraph->Release(); } @@ -921,7 +921,7 @@ namespace Phonon { FILTER_INFO info; filter->QueryFilterInfo(&info); - qDebug() << "found a decoder filter" << QString::fromUtf16(info.achName); + qDebug() << "found a decoder filter" << QString((const QChar *)info.achName); if (info.pGraph) { info.pGraph->Release(); } @@ -937,7 +937,7 @@ namespace Phonon { FILTER_INFO info; filter->QueryFilterInfo(&info); - qDebug() << Q_FUNC_INFO << QString::fromUtf16(info.achName); + qDebug() << Q_FUNC_INFO << QString((const QChar *)info.achName); if (info.pGraph) { info.pGraph->Release(); } @@ -956,7 +956,7 @@ namespace Phonon { FILTER_INFO info; filter->QueryFilterInfo(&info); - qDebug() << Q_FUNC_INFO << QString::fromUtf16(info.achName); + qDebug() << Q_FUNC_INFO << QString((const QChar *)info.achName); if (info.pGraph) { info.pGraph->Release(); } @@ -990,7 +990,7 @@ namespace Phonon { FILTER_INFO info; filter->QueryFilterInfo(&info); - qDebug() << "found a demuxer filter" << QString::fromUtf16(info.achName); + qDebug() << "found a demuxer filter" << QString((const QChar *)info.achName); if (info.pGraph) { info.pGraph->Release(); } diff --git a/src/3rdparty/phonon/waveout/mediaobject.cpp b/src/3rdparty/phonon/waveout/mediaobject.cpp index db71942..08af4ee 100644 --- a/src/3rdparty/phonon/waveout/mediaobject.cpp +++ b/src/3rdparty/phonon/waveout/mediaobject.cpp @@ -50,7 +50,7 @@ namespace Phonon { ushort b[256]; waveOutGetErrorText(error, (LPWSTR)b, 256); - return QString::fromUtf16(b); + return QString((const QChar *)b); } class WorkerThread : public QThread diff --git a/src/corelib/io/qprocess_symbian.cpp b/src/corelib/io/qprocess_symbian.cpp index 75cde51..07d10ad 100644 --- a/src/corelib/io/qprocess_symbian.cpp +++ b/src/corelib/io/qprocess_symbian.cpp @@ -1002,7 +1002,7 @@ bool QProcessPrivate::waitForDeadChild() TExitCategoryName catName = symbianProcess->ExitCategory(); qDebug() << "QProcessPrivate::waitForDeadChild() dead with exitCode" << exitCode << ", crashed:" << crashed - << ", category:" << QString::fromUtf16(catName.Ptr()); + << ", category:" << QString((const QChar *)catName.Ptr()); #endif } else { QPROCESS_DEBUG_PRINT("QProcessPrivate::waitForDeadChild() not dead!"); diff --git a/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp b/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp index 955a880..67dc90c 100644 --- a/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp +++ b/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp @@ -218,7 +218,7 @@ void QAudioDeviceInfoInternal::updateLists() for(i=0;i QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode) for(i=0;i QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode) for(i=0;i &storage) value = qMakeDate(storage.takeFirst()); break; case QVariant::String: - value = QString::fromUtf16( - reinterpret_cast(storage.takeFirst().constData())); + value = QString( + reinterpret_cast(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(errbuf)); + return QString(reinterpret_cast(errbuf)); } void qOraWarning(const char* msg, OCIError *err) @@ -989,8 +989,7 @@ int QOCICols::readPiecewise(QVector &values, int index) } else { if (isStringField) { QString str = values.at(fieldNum + index).toString(); - str += QString::fromUtf16(reinterpret_cast(col), - chunkSize / 2); + str += QString(reinterpret_cast(col), chunkSize / 2); values[fieldNum + index] = str; fieldInf[fieldNum].ind = 0; } else { @@ -1457,7 +1456,7 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVector &boundValues, b break; case SQLT_STR: - (*list)[r] = QString::fromUtf16(reinterpret_cast(data + (*list)[r] = QString(reinterpret_cast(data + r * columns[i].maxLen)); break; @@ -1608,7 +1607,7 @@ void QOCICols::getValues(QVector &v, int index) } // else fall through case QVariant::String: - v[index + i] = QString::fromUtf16(reinterpret_cast(fld.data)); + v[index + i] = QString(reinterpret_cast(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(vertxt)); + versionStr = QString(reinterpret_cast(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 18bc743..fab3ab3 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 d3be304..24dcad9 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(sqlite3_errmsg16(access))), + QString(reinterpret_cast(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(sqlite3_column_name16(stmt, i)) + QString colName = QString(reinterpret_cast( + sqlite3_column_name16(stmt, i)) ).remove(QLatin1Char('"')); // must use typeName for resolving the type to match QSqliteDriver::record - QString typeName = QString::fromUtf16( - static_cast(sqlite3_column_decltype16(stmt, i))); + QString typeName = QString(reinterpret_cast( + sqlite3_column_decltype16(stmt, i))); int dotIdx = colName.lastIndexOf(QLatin1Char('.')); QSqlField fld(colName.mid(dotIdx == -1 ? 0 : dotIdx + 1), qGetColumnType(typeName)); -- cgit v0.12