From 2fdb5240d46fb6981d93b7ccbd8400a96a1f4981 Mon Sep 17 00:00:00 2001 From: Lib Date: Fri, 8 May 2026 12:13:15 +0000 Subject: [PATCH] settings: devirtualize SettingsInterface SettingsInterface was a base class with five pure-virtual config-getter methods, defined in core/settings.h. There has only ever been one concrete subclass: LibretroSettingsInterface (in libretro/), which backs every GetXxxValue call with a single retro_environment_callback to RETRO_ENVIRONMENT_GET_VARIABLE. The single-impl shape means every si.GetBoolValue / si.GetIntValue / si.GetStringValue call in Settings::Load and elsewhere goes through a vtable indirection that resolves to exactly one place. Settings::Load issues 61 such calls, and runs at boot plus on every libretro core-options change. The cost per call is small (~2 ns per virtual dispatch on modern CPUs), so the wall-clock saving is modest, but the abstraction itself buys nothing - there is no second implementation, no plan to add one (the core target is libretro-only), and no use case where the indirection would help. Drop the base class: - Remove 'class SettingsInterface' from core/settings.h, along with its virtual destructor and five pure virtuals. - Remove the SettingsInterface destructor definition from core/settings.cpp. - Make LibretroSettingsInterface a plain class with non-virtual methods (drop the 'override' keyword and the public-inheritance base). - Change Settings::Load's signature from (SettingsInterface&) to (LibretroSettingsInterface&). The one caller already passes a LibretroSettingsInterface, so no call site needs to change. - Forward-declare LibretroSettingsInterface in core/settings.h (the type only appears as a reference in Load's signature) and include the libretro header from settings.cpp where the member function calls actually have to see the definition. The forward-declaration plus include-from-cpp pattern keeps core/settings.h free of libretro headers - a header-level layering nicety. The cpp-level dependency is an existing pattern (multiple core/ TUs already include libretro/ headers - gpu_hw_d3d11.cpp, gpu_hw_opengl.cpp, gpu_hw_vulkan.cpp, texture_replacements.cpp). Linux x64 build still warning-clean. .so size drops from 8048432 to 8047800 bytes (-632) from removing the SettingsInterface vtable, its typeinfo, the virtual destructor, and the indirect-call sites in Settings::Load. 25 retro_* exports unchanged. Behaviour is identical (same calls, same arguments, just direct now). --- src/core/settings.cpp | 5 ++--- src/core/settings.h | 15 ++------------- src/libretro/libretro_settings_interface.h | 16 +++++++++------- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/core/settings.cpp b/src/core/settings.cpp index b0c7e98e..923d1380 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -3,6 +3,7 @@ #include "common/string_util.h" #include "host_display.h" #include "host_interface.h" +#include "libretro/libretro_settings_interface.h" #include #include #include @@ -10,8 +11,6 @@ Settings g_settings; -SettingsInterface::~SettingsInterface() = default; - const char* SettingInfo::StringDefaultValue() const { return default_value ? default_value : ""; @@ -132,7 +131,7 @@ void Settings::UpdateOverclockActive() cpu_overclock_active = (cpu_overclock_enable && (cpu_overclock_numerator != 1 || cpu_overclock_denominator != 1)); } -void Settings::Load(SettingsInterface& si) +void Settings::Load(LibretroSettingsInterface& si) { region = ParseConsoleRegionName( diff --git a/src/core/settings.h b/src/core/settings.h index b6a89f57..5e6ef86e 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -7,18 +7,7 @@ #include #include -class SettingsInterface -{ -public: - virtual ~SettingsInterface(); - - virtual int GetIntValue(const char* section, const char* key, int default_value = 0) = 0; - virtual float GetFloatValue(const char* section, const char* key, float default_value = 0.0f) = 0; - virtual bool GetBoolValue(const char* section, const char* key, bool default_value = false) = 0; - virtual std::string GetStringValue(const char* section, const char* key, const char* default_value = "") = 0; - - virtual std::vector GetStringList(const char* section, const char* key) = 0; -}; +class LibretroSettingsInterface; struct SettingInfo { @@ -205,7 +194,7 @@ struct Settings DEFAULT_GPU_MAX_RUN_AHEAD = 128, DEFAULT_VRAM_WRITE_DUMP_WIDTH_THRESHOLD = 128, DEFAULT_VRAM_WRITE_DUMP_HEIGHT_THRESHOLD = 128; - void Load(SettingsInterface& si); + void Load(LibretroSettingsInterface& si); static std::optional ParseLogLevelName(const char* str); static const char* GetLogLevelName(LogLevel level); diff --git a/src/libretro/libretro_settings_interface.h b/src/libretro/libretro_settings_interface.h index 8dce87e9..b1fccea4 100644 --- a/src/libretro/libretro_settings_interface.h +++ b/src/libretro/libretro_settings_interface.h @@ -1,13 +1,15 @@ #pragma once -#include "core/settings.h" +#include "core/types.h" +#include +#include -class LibretroSettingsInterface : public SettingsInterface +class LibretroSettingsInterface { public: - int GetIntValue(const char* section, const char* key, int default_value = 0) override; - float GetFloatValue(const char* section, const char* key, float default_value = 0.0f) override; - bool GetBoolValue(const char* section, const char* key, bool default_value = false) override; - std::string GetStringValue(const char* section, const char* key, const char* default_value = "") override; + int GetIntValue(const char* section, const char* key, int default_value = 0); + float GetFloatValue(const char* section, const char* key, float default_value = 0.0f); + bool GetBoolValue(const char* section, const char* key, bool default_value = false); + std::string GetStringValue(const char* section, const char* key, const char* default_value = ""); - std::vector GetStringList(const char* section, const char* key) override; + std::vector GetStringList(const char* section, const char* key); };