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>
This commit is contained in:
parent
1a872e5ff2
commit
b5e0bb9152
@ -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()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user