From b5e0bb9152d5ffd737f8cc99aa05d6625fc585c2 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 29 May 2019 15:29:23 +0200 Subject: QWindowsFileSystemWatcher: optimize qWarning() use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The first two changes avoid creation of a temporary QString and QByteArray each, by realisiing that QChar is more-or-less wchar_t on Windows and so we can just use %ls to print the wchar_t array directly. In msgFindNextFailed(), remove the inline keyword and mark the function as cold (not sure this has any effect on Windows). When building the result, don't use QTextStream. Everything that is streamed is text, so just use QString::op+=. When using the result, use qUtf16Printable and %ls instead of qPrintable and %s, to avoid the creation of a temporary QByteArray. Change-Id: I09f576b894761fe342109b386c1de3532200e03c Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Thiago Macieira --- src/corelib/io/qfilesystemwatcher_win.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/corelib/io/qfilesystemwatcher_win.cpp b/src/corelib/io/qfilesystemwatcher_win.cpp index aadfe7963d..81ed694d95 100644 --- a/src/corelib/io/qfilesystemwatcher_win.cpp +++ b/src/corelib/io/qfilesystemwatcher_win.cpp @@ -306,8 +306,7 @@ void QWindowsRemovableDriveListener::addPath(const QString &p) OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, // Volume requires BACKUP_SEMANTICS 0); if (volumeHandle == INVALID_HANDLE_VALUE) { - qErrnoWarning("CreateFile %s failed.", - qPrintable(QString::fromWCharArray(devicePath))); + qErrnoWarning("CreateFile %ls failed.", devicePath); return; } @@ -324,8 +323,7 @@ void QWindowsRemovableDriveListener::addPath(const QString &p) // closed. Do it here to avoid having to close/reopen in lock message handling. CloseHandle(volumeHandle); if (!re.devNotify) { - qErrnoWarning("RegisterDeviceNotification %s failed.", - qPrintable(QString::fromWCharArray(devicePath))); + qErrnoWarning("RegisterDeviceNotification %ls failed.", devicePath); return; } @@ -641,15 +639,15 @@ QWindowsFileSystemWatcherEngineThread::~QWindowsFileSystemWatcherEngineThread() } } -static inline QString msgFindNextFailed(const QWindowsFileSystemWatcherEngineThread::PathInfoHash &pathInfos) +Q_DECL_COLD_FUNCTION +static QString msgFindNextFailed(const QWindowsFileSystemWatcherEngineThread::PathInfoHash &pathInfos) { - QString result; - QTextStream str(&result); - str << "QFileSystemWatcher: FindNextChangeNotification failed for"; + QString str; + str += QLatin1String("QFileSystemWatcher: FindNextChangeNotification failed for"); for (const QWindowsFileSystemWatcherEngine::PathInfo &pathInfo : pathInfos) - str << " \"" << QDir::toNativeSeparators(pathInfo.absolutePath) << '"'; - str << ' '; - return result; + str += QLatin1String(" \"") + QDir::toNativeSeparators(pathInfo.absolutePath) + QLatin1Char('"'); + str += QLatin1Char(' '); + return str; } void QWindowsFileSystemWatcherEngineThread::run() @@ -695,7 +693,7 @@ void QWindowsFileSystemWatcherEngineThread::run() fakeRemove = true; } - qErrnoWarning(error, "%s", qPrintable(msgFindNextFailed(h))); + qErrnoWarning(error, "%ls", qUtf16Printable(msgFindNextFailed(h))); } QMutableHashIterator it(h); while (it.hasNext()) { -- cgit v1.2.3