From 9bd1dae41d8703e70196397722f98364bae63035 Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Thu, 22 Aug 2024 19:16:36 -0700 Subject: [PATCH] Modernize `std::fill` with ranges In DSPCore.cpp, there were two `std::fill` uses that could be simplified using `std::fill_n`. Due to their proximity with other `std::fill` algorithms being modernized with ranges, I chose to make these examples into the rare `std::ranges::fill_n`. --- Source/Core/Core/DSP/DSPCore.cpp | 12 ++++++------ Source/Core/Core/DSP/Jit/x64/DSPEmitter.cpp | 2 +- Source/Core/Core/FifoPlayer/FifoRecorder.cpp | 4 ++-- Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp | 2 +- Source/Core/Core/PowerPC/PPCCache.cpp | 6 +++--- Source/Core/Core/PowerPC/PowerPC.cpp | 8 ++++---- .../ControllerInterface/DInput/DInputJoystick.cpp | 2 +- Source/Core/VideoCommon/FramebufferManager.cpp | 4 ++-- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Source/Core/Core/DSP/DSPCore.cpp b/Source/Core/Core/DSP/DSPCore.cpp index dadc8effa6..b6d89064b5 100644 --- a/Source/Core/Core/DSP/DSPCore.cpp +++ b/Source/Core/Core/DSP/DSPCore.cpp @@ -143,20 +143,20 @@ bool SDSP::Initialize(const DSPInitOptions& opts) std::memset(&r, 0, sizeof(r)); - std::fill(std::begin(reg_stack_ptrs), std::end(reg_stack_ptrs), 0); + std::ranges::fill(reg_stack_ptrs, 0); for (auto& stack : reg_stacks) - std::fill(std::begin(stack), std::end(stack), 0); + std::ranges::fill(stack, 0); // Fill IRAM with HALT opcodes. - std::fill(iram, iram + DSP_IRAM_SIZE, 0x0021); + std::ranges::fill_n(iram, DSP_IRAM_SIZE, 0x0021); // Just zero out DRAM. - std::fill(dram, dram + DSP_DRAM_SIZE, 0); + std::ranges::fill_n(dram, DSP_DRAM_SIZE, 0); // Copied from a real console after the custom UCode has been loaded. // These are the indexing wrapping registers. - std::fill(std::begin(r.wr), std::end(r.wr), 0xffff); + std::ranges::fill(r.wr, 0xffff); r.sr |= SR_INT_ENABLE; r.sr |= SR_EXT_INT_ENABLE; @@ -172,7 +172,7 @@ bool SDSP::Initialize(const DSPInitOptions& opts) void SDSP::Reset() { pc = DSP_RESET_VECTOR; - std::fill(std::begin(r.wr), std::end(r.wr), 0xffff); + std::ranges::fill(r.wr, 0xffff); } void SDSP::Shutdown() diff --git a/Source/Core/Core/DSP/Jit/x64/DSPEmitter.cpp b/Source/Core/Core/DSP/Jit/x64/DSPEmitter.cpp index 6d8527f657..7066209530 100644 --- a/Source/Core/Core/DSP/Jit/x64/DSPEmitter.cpp +++ b/Source/Core/Core/DSP/Jit/x64/DSPEmitter.cpp @@ -40,7 +40,7 @@ DSPEmitter::DSPEmitter(DSPCore& dsp) m_stub_entry_point = CompileStub(); // Clear all of the block references - std::fill(m_blocks.begin(), m_blocks.end(), (DSPCompiledCode)m_stub_entry_point); + std::ranges::fill(m_blocks, (DSPCompiledCode)m_stub_entry_point); } DSPEmitter::~DSPEmitter() diff --git a/Source/Core/Core/FifoPlayer/FifoRecorder.cpp b/Source/Core/Core/FifoPlayer/FifoRecorder.cpp index c354a5fdf7..32abaf1997 100644 --- a/Source/Core/Core/FifoPlayer/FifoRecorder.cpp +++ b/Source/Core/Core/FifoPlayer/FifoRecorder.cpp @@ -240,8 +240,8 @@ void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb) m_Ram.resize(memory.GetRamSize()); m_ExRam.resize(memory.GetExRamSize()); - std::fill(m_Ram.begin(), m_Ram.end(), 0); - std::fill(m_ExRam.begin(), m_ExRam.end(), 0); + std::ranges::fill(m_Ram, 0); + std::ranges::fill(m_ExRam, 0); m_File->SetIsWii(m_system.IsWii()); diff --git a/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp b/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp index fa3121bb6c..2c510fb394 100644 --- a/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp @@ -452,7 +452,7 @@ bool Wiimote::ProcessReadDataRequest() reply.address = Common::swap16(m_read_request.address); // Pre-fill with zeros in case of read-error or read < 16-bytes: - std::fill(std::begin(reply.data), std::end(reply.data), 0x00); + std::ranges::fill(reply.data, 0x00); ErrorCode error_code = ErrorCode::Success; diff --git a/Source/Core/Core/PowerPC/PPCCache.cpp b/Source/Core/Core/PowerPC/PPCCache.cpp index 0213a47c38..3d351f97d1 100644 --- a/Source/Core/Core/PowerPC/PPCCache.cpp +++ b/Source/Core/Core/PowerPC/PPCCache.cpp @@ -100,9 +100,9 @@ void Cache::Reset() valid.fill(0); plru.fill(0); modified.fill(0); - std::fill(lookup_table.begin(), lookup_table.end(), 0xFF); - std::fill(lookup_table_ex.begin(), lookup_table_ex.end(), 0xFF); - std::fill(lookup_table_vmem.begin(), lookup_table_vmem.end(), 0xFF); + std::ranges::fill(lookup_table, 0xFF); + std::ranges::fill(lookup_table_ex, 0xFF); + std::ranges::fill(lookup_table_vmem, 0xFF); } void InstructionCache::Reset(JitInterface& jit_interface) diff --git a/Source/Core/Core/PowerPC/PowerPC.cpp b/Source/Core/Core/PowerPC/PowerPC.cpp index e97db77fc7..fec63c86d5 100644 --- a/Source/Core/Core/PowerPC/PowerPC.cpp +++ b/Source/Core/Core/PowerPC/PowerPC.cpp @@ -128,10 +128,10 @@ void PowerPCManager::DoState(PointerWrap& p) void PowerPCManager::ResetRegisters() { - std::fill(std::begin(m_ppc_state.ps), std::end(m_ppc_state.ps), PairedSingle{}); - std::fill(std::begin(m_ppc_state.sr), std::end(m_ppc_state.sr), 0U); - std::fill(std::begin(m_ppc_state.gpr), std::end(m_ppc_state.gpr), 0U); - std::fill(std::begin(m_ppc_state.spr), std::end(m_ppc_state.spr), 0U); + std::ranges::fill(m_ppc_state.ps, PairedSingle{}); + std::ranges::fill(m_ppc_state.sr, 0U); + std::ranges::fill(m_ppc_state.gpr, 0U); + std::ranges::fill(m_ppc_state.spr, 0U); // Gamecube: // 0x00080200 = lonestar 2.0 diff --git a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp index 5d3e353a0a..a78c310f24 100644 --- a/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp +++ b/Source/Core/InputCommon/ControllerInterface/DInput/DInputJoystick.cpp @@ -183,7 +183,7 @@ Joystick::Joystick(const LPDIRECTINPUTDEVICE8 device) : m_device(device) // Set hats to center: // "The center position is normally reported as -1" -MSDN - std::fill(std::begin(m_state_in.rgdwPOV), std::end(m_state_in.rgdwPOV), -1); + std::ranges::fill(m_state_in.rgdwPOV, -1); } Joystick::~Joystick() diff --git a/Source/Core/VideoCommon/FramebufferManager.cpp b/Source/Core/VideoCommon/FramebufferManager.cpp index 3c83bce2c4..044b94a5de 100644 --- a/Source/Core/VideoCommon/FramebufferManager.cpp +++ b/Source/Core/VideoCommon/FramebufferManager.cpp @@ -764,9 +764,9 @@ bool FramebufferManager::CreateReadbackFramebuffer() } m_efb_color_cache.tiles.resize(total_tiles); - std::fill(m_efb_color_cache.tiles.begin(), m_efb_color_cache.tiles.end(), EFBCacheTile{false, 0}); + std::ranges::fill(m_efb_color_cache.tiles, EFBCacheTile{false, 0}); m_efb_depth_cache.tiles.resize(total_tiles); - std::fill(m_efb_depth_cache.tiles.begin(), m_efb_depth_cache.tiles.end(), EFBCacheTile{false, 0}); + std::ranges::fill(m_efb_depth_cache.tiles, EFBCacheTile{false, 0}); return true; }