diff --git a/openVulkanoCpp/Host/Linux/SystemInfo.cpp b/openVulkanoCpp/Host/Linux/SystemInfo.cpp index 64ad209..a47e77e 100644 --- a/openVulkanoCpp/Host/Linux/SystemInfo.cpp +++ b/openVulkanoCpp/Host/Linux/SystemInfo.cpp @@ -73,11 +73,7 @@ namespace OpenVulkano size_t SystemInfo::GetSystemRam() { - static size_t ram; - if (ram == 0) - { - ram = ReadMemInfo("MemTotal"); - } + static const size_t ram = ReadMemInfo("MemTotal"); return ram; } @@ -314,11 +310,7 @@ namespace OpenVulkano size_t SystemInfo::GetCpuThreadCount() { - static size_t threadCount; - if (threadCount == 0) - { - threadCount = std::thread::hardware_concurrency(); - } + static const size_t threadCount = std::thread::hardware_concurrency(); return threadCount; } diff --git a/openVulkanoCpp/Host/MacOS/SystemInfo.mm b/openVulkanoCpp/Host/MacOS/SystemInfo.mm index 1d0711f..b5d4d41 100644 --- a/openVulkanoCpp/Host/MacOS/SystemInfo.mm +++ b/openVulkanoCpp/Host/MacOS/SystemInfo.mm @@ -7,6 +7,7 @@ #include "Host/SystemInfo.hpp" #include "Base/Logger.hpp" #include +#include #include #include @@ -24,11 +25,7 @@ namespace OpenVulkano size_t SystemInfo::GetSystemRam() { - static size_t ram; - if (ram == 0) - { - ram = [NSProcessInfo processInfo].physicalMemory; - } + static const size_t ram = [NSProcessInfo processInfo].physicalMemory; return ram; } @@ -72,21 +69,13 @@ namespace OpenVulkano std::string SystemInfo::GetHostName() { - static std::string hostName; - if (hostName.empty()) - { - hostName = [[NSProcessInfo processInfo].hostName UTF8String]; - } + static const std::string hostName = [[NSProcessInfo processInfo].hostName UTF8String]; return hostName; } std::string SystemInfo::GetDeviceName() { - static std::string devName; - if (devName.empty()) - { - devName = "Mac"; //TODO - } + static const std::string devName = "Mac"; //TODO return devName; } @@ -114,7 +103,7 @@ namespace OpenVulkano OsVersion SystemInfo::GetOsVersion() { - static OsVersion osVersion; + static OsVersion osVersion = {}; if (osVersion.major == 0 && osVersion.minor == 0) { NSOperatingSystemVersion sysVersion = [NSProcessInfo processInfo].operatingSystemVersion; @@ -126,13 +115,7 @@ namespace OpenVulkano std::string SystemInfo::GetOsNameHumanReadable() { - static std::string hrName; - if (hrName.empty()) - { - std::stringstream name; - name << GetOsName() << ' ' << GetOsVersion().major; - hrName = name.str(); - } + static const std::string hrName = fmt::format("{} {}", GetOsName(), GetOsVersion().major); return hrName; } @@ -143,21 +126,13 @@ namespace OpenVulkano size_t SystemInfo::GetCpuCoreCount() { - static size_t coreCount; - if (coreCount == 0) - { - coreCount = [NSProcessInfo processInfo].processorCount; - } + static const size_t coreCount = [NSProcessInfo processInfo].processorCount; return coreCount; } size_t SystemInfo::GetCpuThreadCount() { - static size_t procCount; - if (procCount == 0) - { - procCount = [NSProcessInfo processInfo].activeProcessorCount; - } + static size_t procCount = [NSProcessInfo processInfo].activeProcessorCount; return procCount; } diff --git a/openVulkanoCpp/Host/Windows/SystemInfo.cpp b/openVulkanoCpp/Host/Windows/SystemInfo.cpp index 7832435..2f4eecc 100644 --- a/openVulkanoCpp/Host/Windows/SystemInfo.cpp +++ b/openVulkanoCpp/Host/Windows/SystemInfo.cpp @@ -426,7 +426,7 @@ namespace OpenVulkano OsVersion SystemInfo::GetOsVersion() { - static OsVersion osVersion; + static OsVersion osVersion = {}; if (osVersion.major == 0 && osVersion.minor == 0) { NTSTATUS(WINAPI * RtlGetVersion)(LPOSVERSIONINFOEXW); @@ -441,11 +441,7 @@ namespace OpenVulkano std::string SystemInfo::GetOsNameHumanReadable() { - static std::string osName; - if (osName.empty()) - { - osName = GetHumanReadableOSName(); - } + static const std::string osName = GetHumanReadableOSName(); return osName; } @@ -456,7 +452,7 @@ namespace OpenVulkano size_t SystemInfo::GetCpuCoreCount() { - static size_t coreCount; + static size_t coreCount = 0; if (coreCount == 0) { DWORD bufferSize = 0; diff --git a/openVulkanoCpp/Host/iOS/SystemInfo.mm b/openVulkanoCpp/Host/iOS/SystemInfo.mm index e3ee351..af0c922 100644 --- a/openVulkanoCpp/Host/iOS/SystemInfo.mm +++ b/openVulkanoCpp/Host/iOS/SystemInfo.mm @@ -27,11 +27,7 @@ namespace OpenVulkano size_t SystemInfo::GetSystemRam() { - static size_t ram; - if (ram == 0) - { - ram = [NSProcessInfo processInfo].physicalMemory; - } + static const size_t ram = [NSProcessInfo processInfo].physicalMemory; return ram; } @@ -75,21 +71,13 @@ namespace OpenVulkano std::string SystemInfo::GetHostName() { - static std::string hostName; - if (hostName.empty()) - { - hostName = [[NSProcessInfo processInfo].hostName UTF8String]; - } + static const std::string hostName = [[NSProcessInfo processInfo].hostName UTF8String]; return hostName; } std::string SystemInfo::GetDeviceName() { - static std::string devName; - if (devName.empty()) - { - devName = [[[UIDevice currentDevice] name] UTF8String]; - } + static const std::string devName = [[[UIDevice currentDevice] name] UTF8String]; return devName; } @@ -113,17 +101,13 @@ namespace OpenVulkano std::string SystemInfo::GetOsName() { - static std::string osName; - if (osName.empty()) - { - osName = [[[UIDevice currentDevice] systemName] UTF8String]; - } + static const std::string osName = [[[UIDevice currentDevice] systemName] UTF8String]; return osName; } OsVersion SystemInfo::GetOsVersion() { - static OsVersion osv; + static OsVersion osv = {}; if (osv.major == 0 && osv.minor == 0) { NSOperatingSystemVersion osVersion = [NSProcessInfo processInfo].operatingSystemVersion; @@ -170,21 +154,13 @@ namespace OpenVulkano size_t SystemInfo::GetCpuCoreCount() { - static size_t coreCount; - if (coreCount == 0) - { - coreCount = [NSProcessInfo processInfo].processorCount; - } + static const size_t coreCount = [NSProcessInfo processInfo].processorCount; return coreCount; } size_t SystemInfo::GetCpuThreadCount() { - static size_t threadCount; - if (threadCount == 0) - { - threadCount = [NSProcessInfo processInfo].activeProcessorCount; - } + static const size_t threadCount = [NSProcessInfo processInfo].activeProcessorCount; return threadCount; }