diff options
author | Yuhang Zhao <2546789017@qq.com> | 2022-08-17 19:55:21 +0800 |
---|---|---|
committer | Yuhang Zhao <2546789017@qq.com> | 2022-08-23 11:24:15 +0800 |
commit | 1270284f8dc753205034e7958c2a4063d1d15a7b (patch) | |
tree | 2a838e2cd7095d72caed1b107270a149275250e3 /src/corelib/plugin | |
parent | 00618db5ffbe9afb14a1a86e722c826cc6e865d0 (diff) |
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>
Diffstat (limited to 'src/corelib/plugin')
-rw-r--r-- | src/corelib/plugin/qsystemlibrary.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/corelib/plugin/qsystemlibrary.cpp b/src/corelib/plugin/qsystemlibrary.cpp index 503bb25206..f1475b4a67 100644 --- a/src/corelib/plugin/qsystemlibrary.cpp +++ b/src/corelib/plugin/qsystemlibrary.cpp @@ -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 */) |