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

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