Removed redundant if statements where possible

This commit is contained in:
Vladyslav Baranovskyi
2024-12-20 16:10:10 +02:00
parent 90440b3f34
commit 947faebe9c
4 changed files with 20 additions and 81 deletions

View File

@@ -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;
}

View File

@@ -7,6 +7,7 @@
#include "Host/SystemInfo.hpp"
#include "Base/Logger.hpp"
#include <sstream>
#include <fmt/core.h>
#include <mach/mach.h>
#include <os/proc.h>
@@ -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;
}

View File

@@ -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;

View File

@@ -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;
}