qoperatingsystemversion_win: cache the retrieved version

Make it a static variable to avoid acquiring
the system version multiple times. The system
version won't change at runtime after all.

Pick-to: 6.2
Change-Id: Ic381e5dd7b482fedc9c01242482559ffca9d3f2b
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
Yuhang Zhao 2021-11-02 12:44:34 +08:00
parent 059c48b908
commit 3fe89eec61

View File

@ -110,12 +110,14 @@ OSVERSIONINFOEX qWindowsVersionInfo()
QOperatingSystemVersion QOperatingSystemVersion::current()
{
QOperatingSystemVersion v;
v.m_os = currentType();
const OSVERSIONINFOEX osv = qWindowsVersionInfo();
v.m_major = osv.dwMajorVersion;
v.m_minor = osv.dwMinorVersion;
v.m_micro = osv.dwBuildNumber;
static QOperatingSystemVersion v;
if (v.m_os == Unknown) {
v.m_os = currentType();
const OSVERSIONINFOEX osv = qWindowsVersionInfo();
v.m_major = osv.dwMajorVersion;
v.m_minor = osv.dwMinorVersion;
v.m_micro = osv.dwBuildNumber;
}
return v;
}