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).
This commit is contained in:
Lib 2026-05-08 12:13:15 +00:00 • committed by U-DESKTOP-SPFP6AQ\twistedtechre
commit 2fdb5240d4
3 changed files with 13 additions and 23 deletions

View file

@ -3,6 +3,7 @@
#include "common/string_util.h"
#include "host_display.h"
#include "host_interface.h"
#include "libretro/libretro_settings_interface.h"
#include <algorithm>
#include <array>
#include <cctype>
@ -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(

View file

@ -7,18 +7,7 @@
#include <string>
#include <vector>
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<std::string> 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<LogLevel> ParseLogLevelName(const char* str);
static const char* GetLogLevelName(LogLevel level);

View file

@ -1,13 +1,15 @@
#pragma once
#include "core/settings.h"
#include "core/types.h"
#include <string>
#include <vector>
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<std::string> GetStringList(const char* section, const char* key) override;
std::vector<std::string> GetStringList(const char* section, const char* key);
};