From a34f221782af6b3ee1b6adc646db2262a3d89b51 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Wed, 16 Aug 2023 19:15:22 +0200 Subject: [PATCH] Core/PowerPC: Return AvailableCPUCores() as a std::span. --- Source/Core/Core/PowerPC/PowerPC.cpp | 4 ++-- Source/Core/Core/PowerPC/PowerPC.h | 3 ++- Source/Core/DolphinQt/Settings/AdvancedPane.cpp | 10 ++++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Source/Core/Core/PowerPC/PowerPC.cpp b/Source/Core/Core/PowerPC/PowerPC.cpp index 30c9cb2b14..a2a890d5bc 100644 --- a/Source/Core/Core/PowerPC/PowerPC.cpp +++ b/Source/Core/Core/PowerPC/PowerPC.cpp @@ -236,9 +236,9 @@ void PowerPCManager::InitializeCPUCore(CPUCore cpu_core) m_mode = m_cpu_core_base == &interpreter ? CoreMode::Interpreter : CoreMode::JIT; } -const std::vector& AvailableCPUCores() +std::span AvailableCPUCores() { - static const std::vector cpu_cores = { + static constexpr auto cpu_cores = { #ifdef _M_X86_64 CPUCore::JIT64, #elif defined(_M_ARM_64) diff --git a/Source/Core/Core/PowerPC/PowerPC.h b/Source/Core/Core/PowerPC/PowerPC.h index 42545f2c1f..ffaa3630d7 100644 --- a/Source/Core/Core/PowerPC/PowerPC.h +++ b/Source/Core/Core/PowerPC/PowerPC.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -238,7 +239,7 @@ static_assert(offsetof(PowerPC::PowerPCState, above_fits_in_first_0x100) <= 0x10 #endif #endif -const std::vector& AvailableCPUCores(); +std::span AvailableCPUCores(); CPUCore DefaultCPUCore(); class PowerPCManager diff --git a/Source/Core/DolphinQt/Settings/AdvancedPane.cpp b/Source/Core/DolphinQt/Settings/AdvancedPane.cpp index 438222a17e..af50a3f7e9 100644 --- a/Source/Core/DolphinQt/Settings/AdvancedPane.cpp +++ b/Source/Core/DolphinQt/Settings/AdvancedPane.cpp @@ -190,9 +190,11 @@ void AdvancedPane::CreateLayout() void AdvancedPane::ConnectLayout() { - connect(m_cpu_emulation_engine_combobox, - static_cast(&QComboBox::currentIndexChanged), [](int index) { - Config::SetBaseOrCurrent(Config::MAIN_CPU_CORE, PowerPC::AvailableCPUCores()[index]); + connect(m_cpu_emulation_engine_combobox, qOverload(&QComboBox::currentIndexChanged), + [](int index) { + const auto cpu_cores = PowerPC::AvailableCPUCores(); + if (index >= 0 && static_cast(index) < cpu_cores.size()) + Config::SetBaseOrCurrent(Config::MAIN_CPU_CORE, cpu_cores[index]); }); connect(m_cpu_clock_override_checkbox, &QCheckBox::toggled, [this](bool enable_clock_override) { @@ -243,7 +245,7 @@ void AdvancedPane::Update() const bool enable_ram_override_widgets = Config::Get(Config::MAIN_RAM_OVERRIDE_ENABLE); const bool enable_custom_rtc_widgets = Config::Get(Config::MAIN_CUSTOM_RTC_ENABLE) && !running; - const std::vector& available_cpu_cores = PowerPC::AvailableCPUCores(); + const auto available_cpu_cores = PowerPC::AvailableCPUCores(); const auto cpu_core = Config::Get(Config::MAIN_CPU_CORE); for (size_t i = 0; i < available_cpu_cores.size(); ++i) {