QSystemLibrary: Cache the system directory path
The system directory path won't change during the lifetime of the application, so cache it to avoid querying it for multiple times. Change-Id: I302285794d491d581d74a93e7ba9affc6379c681 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
00618db5ff
commit
1270284f8d
|
|
@ -44,15 +44,17 @@ extern QString qAppFileName();
|
|||
|
||||
static QString qSystemDirectory()
|
||||
{
|
||||
QVarLengthArray<wchar_t, MAX_PATH> fullPath;
|
||||
|
||||
UINT retLen = ::GetSystemDirectory(fullPath.data(), MAX_PATH);
|
||||
if (retLen > MAX_PATH) {
|
||||
fullPath.resize(retLen);
|
||||
retLen = ::GetSystemDirectory(fullPath.data(), retLen);
|
||||
}
|
||||
// in some rare cases retLen might be 0
|
||||
return QString::fromWCharArray(fullPath.constData(), int(retLen));
|
||||
static const QString result = []() -> QString {
|
||||
QVarLengthArray<wchar_t, MAX_PATH> fullPath = {};
|
||||
UINT retLen = ::GetSystemDirectoryW(fullPath.data(), MAX_PATH);
|
||||
if (retLen > MAX_PATH) {
|
||||
fullPath.resize(retLen);
|
||||
retLen = ::GetSystemDirectoryW(fullPath.data(), retLen);
|
||||
}
|
||||
// in some rare cases retLen might be 0
|
||||
return QString::fromWCharArray(fullPath.constData(), int(retLen));
|
||||
}();
|
||||
return result;
|
||||
}
|
||||
|
||||
HINSTANCE QSystemLibrary::load(const wchar_t *libraryName, bool onlySystemDirectory /* = true */)
|
||||
|
|
|
|||
Loading…
Reference in New Issue