summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfilesystemwatcher_win.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2019-05-29 15:29:23 +0200
committerMarc Mutz <marc.mutz@kdab.com>2019-05-29 18:24:29 +0200
commitb5e0bb9152d5ffd737f8cc99aa05d6625fc585c2 (patch)
tree23dc21aa70cee1c0c555e32f0c3db82843289eb2 /src/corelib/io/qfilesystemwatcher_win.cpp
parent1a872e5ff2ce538960c54986e09dcb5eb8d4bd63 (diff)
QWindowsFileSystemWatcher: optimize qWarning() use
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 <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qfilesystemwatcher_win.cpp')
-rw-r--r--src/corelib/io/qfilesystemwatcher_win.cpp22
1 files changed, 10 insertions, 12 deletions
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<QFileSystemWatcherPathKey, QWindowsFileSystemWatcherEngine::PathInfo> it(h);
while (it.hasNext()) {