Files
sphaira/sphaira/source/option.cpp
ITotalJustice f7c5ccfa87 huge optimisations (see below). Build with c++26 and c23.
- build with c++26 and c23, fixes warnings due to this change.
- use #embed over romfs where applicable.
- load all configs upfront in the app menu, massively improves boot time
- enable boost mode during load/scan time in all (slow loading) menus, huge load time improvement.
- enable boost mode when exiting the app, to speed up closing all the menus and saving the config.
- reduce the size of the nro nacp when loading to just the title + author + display version.
- add option to enable boost mode for all progress bar menus, huge perf improvement again.
- remove unused launch_count var from the playlog file.
- display full path when dumping.
- optimise appstore unzip code by iterating through the zip rather than finding a specific file, reduces retroarch extract time from 52s to 26s.

overall, this commit has reduced boot time from 0.4s to 0.3s and massively increased load times of other menus.
(it also reduced the binary size by 4kb, so yay)
2025-05-25 20:57:03 +01:00

103 lines
3.1 KiB
C++

#include <minIni.h>
#include <type_traits>
#include "option.hpp"
#include "app.hpp"
#include <cctype>
#include <cstring>
#include <cstdlib>
namespace sphaira::option {
namespace {
// these are taken from minini in order to parse a value already loaded in memory.
long getl(const char* LocalBuffer, long def) {
const auto len = strlen(LocalBuffer);
return (len == 0) ? def
: ((len >= 2 && toupper((int)LocalBuffer[1]) == 'X') ? strtol(LocalBuffer, NULL, 16)
: strtol(LocalBuffer, NULL, 10));
}
bool getbool(const char* LocalBuffer, bool def) {
const auto c = toupper(LocalBuffer[0]);
if (c == 'Y' || c == '1' || c == 'T')
return true;
else if (c == 'N' || c == '0' || c == 'F')
return false;
else
return def;
}
} // namespace
template<typename T>
auto OptionBase<T>::GetInternal(const char* name) -> T {
if (!m_value.has_value()) {
if constexpr(std::is_same_v<T, bool>) {
m_value = ini_getbool(m_section.c_str(), name, m_default_value, App::CONFIG_PATH);
} else if constexpr(std::is_same_v<T, long>) {
m_value = ini_getl(m_section.c_str(), name, m_default_value, App::CONFIG_PATH);
} else if constexpr(std::is_same_v<T, std::string>) {
char buf[FS_MAX_PATH];
ini_gets(m_section.c_str(), name, m_default_value.c_str(), buf, sizeof(buf), App::CONFIG_PATH);
m_value = buf;
}
}
return m_value.value();
}
template<typename T>
auto OptionBase<T>::Get() -> T {
return GetInternal(m_name.c_str());
}
template<typename T>
auto OptionBase<T>::GetOr(const char* name) -> T {
if (ini_haskey(m_section.c_str(), m_name.c_str(), App::CONFIG_PATH)) {
return Get();
} else {
return GetInternal(name);
}
}
template<typename T>
void OptionBase<T>::Set(T value) {
m_value = value;
if constexpr(std::is_same_v<T, bool>) {
ini_putl(m_section.c_str(), m_name.c_str(), value, App::CONFIG_PATH);
} else if constexpr(std::is_same_v<T, long>) {
ini_putl(m_section.c_str(), m_name.c_str(), value, App::CONFIG_PATH);
} else if constexpr(std::is_same_v<T, std::string>) {
ini_puts(m_section.c_str(), m_name.c_str(), value.c_str(), App::CONFIG_PATH);
}
}
template<typename T>
auto OptionBase<T>::LoadFrom(const char* section, const char* name, const char* value) -> bool {
return m_section == section && LoadFrom(name, value);
}
template<typename T>
auto OptionBase<T>::LoadFrom(const char* name, const char* value) -> bool {
if (m_name == name) {
if constexpr(std::is_same_v<T, bool>) {
m_value = getbool(value, m_default_value);
} else if constexpr(std::is_same_v<T, long>) {
m_value = getl(value, m_default_value);
} else if constexpr(std::is_same_v<T, std::string>) {
m_value = value;
}
return true;
}
return false;
}
template struct OptionBase<bool>;
template struct OptionBase<long>;
template struct OptionBase<std::string>;
} // namespace sphaira::option