From 7ce170f1385b114572fb9e71eeedfd5567784096 Mon Sep 17 00:00:00 2001 From: mitaclaw <140017135+mitaclaw@users.noreply.github.com> Date: Fri, 27 Sep 2024 22:30:01 -0700 Subject: [PATCH] Modernize `std::copy` with ranges --- Source/Core/Common/Crypto/ec.cpp | 4 ++-- Source/Core/Common/Network.cpp | 4 ++-- Source/Core/Core/FifoPlayer/FifoPlayer.cpp | 2 +- Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp | 2 +- Source/Core/Core/HW/WiiSave.cpp | 2 +- Source/Core/Core/IOS/Crypto/Sha.cpp | 8 ++++---- Source/Core/Core/IOS/ES/Formats.cpp | 2 +- Source/Core/Core/IOS/ES/TitleManagement.cpp | 2 +- Source/Core/Core/IOS/ES/Views.cpp | 2 +- Source/Core/Core/IOS/IOSC.cpp | 2 +- Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp | 4 ++-- Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp | 6 +++--- Source/Core/Core/Movie.cpp | 2 +- Source/Core/Core/SysConf.cpp | 2 +- 14 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Source/Core/Common/Crypto/ec.cpp b/Source/Core/Common/Crypto/ec.cpp index 4cce6ce5dc..1f1b0e6018 100644 --- a/Source/Core/Common/Crypto/ec.cpp +++ b/Source/Core/Common/Crypto/ec.cpp @@ -252,8 +252,8 @@ Signature Sign(const u8* key, const u8* hash) bn_mul(s.data.data(), minv, kk, ec_N, 30); Signature signature; - std::copy(r.data.cbegin(), r.data.cend(), signature.begin()); - std::copy(s.data.cbegin(), s.data.cend(), signature.begin() + 30); + std::ranges::copy(r.data, signature.begin()); + std::ranges::copy(s.data, signature.begin() + 30); return signature; } diff --git a/Source/Core/Common/Network.cpp b/Source/Core/Common/Network.cpp index d8e60ccf1e..ca40eb3fe1 100644 --- a/Source/Core/Common/Network.cpp +++ b/Source/Core/Common/Network.cpp @@ -36,10 +36,10 @@ MACAddress GenerateMacAddress(const MACConsumer type) switch (type) { case MACConsumer::BBA: - std::copy(oui_bba.begin(), oui_bba.end(), mac.begin()); + std::ranges::copy(oui_bba, mac.begin()); break; case MACConsumer::IOS: - std::copy(oui_ios.begin(), oui_ios.end(), mac.begin()); + std::ranges::copy(oui_ios, mac.begin()); break; } diff --git a/Source/Core/Core/FifoPlayer/FifoPlayer.cpp b/Source/Core/Core/FifoPlayer/FifoPlayer.cpp index a7db428b00..8f6a54916e 100644 --- a/Source/Core/Core/FifoPlayer/FifoPlayer.cpp +++ b/Source/Core/Core/FifoPlayer/FifoPlayer.cpp @@ -500,7 +500,7 @@ void FifoPlayer::WriteMemory(const MemoryUpdate& memUpdate) else mem = &memory.GetRAM()[memUpdate.address & memory.GetRamMask()]; - std::copy(memUpdate.data.begin(), memUpdate.data.end(), mem); + std::ranges::copy(memUpdate.data, mem); } void FifoPlayer::WriteFifo(const u8* data, u32 start, u32 end) diff --git a/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp b/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp index 10522842de..f0b899192d 100644 --- a/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp +++ b/Source/Core/Core/HW/SI/SI_DeviceGBAEmu.cpp @@ -93,7 +93,7 @@ int CSIDevice_GBAEmu::RunBuffer(u8* buffer, int request_length) std::vector response = m_core->GetJoybusResponse(); if (response.empty()) return -1; - std::copy(response.begin(), response.end(), buffer); + std::ranges::copy(response, buffer); #ifdef _DEBUG const Common::Log::LogLevel log_level = diff --git a/Source/Core/Core/HW/WiiSave.cpp b/Source/Core/Core/HW/WiiSave.cpp index e706f19afe..b636fb0b2c 100644 --- a/Source/Core/Core/HW/WiiSave.cpp +++ b/Source/Core/Core/HW/WiiSave.cpp @@ -422,7 +422,7 @@ public: if (data) { std::vector file_data_enc(Common::AlignUp(data->size(), BLOCK_SZ)); - std::copy(data->cbegin(), data->cend(), file_data_enc.begin()); + std::ranges::copy(*data, file_data_enc.begin()); m_iosc.Encrypt(IOS::HLE::IOSC::HANDLE_SD_KEY, file_hdr.iv.data(), file_data_enc.data(), file_data_enc.size(), file_data_enc.data(), IOS::PID_ES); if (!m_file.WriteBytes(file_data_enc.data(), file_data_enc.size())) diff --git a/Source/Core/Core/IOS/Crypto/Sha.cpp b/Source/Core/Core/IOS/Crypto/Sha.cpp index de4415e140..a39927157c 100644 --- a/Source/Core/Core/IOS/Crypto/Sha.cpp +++ b/Source/Core/Core/IOS/Crypto/Sha.cpp @@ -33,14 +33,14 @@ std::optional ShaDevice::Open(const OpenRequest& request) static void ConvertContext(const ShaDevice::ShaContext& src, mbedtls_sha1_context* dest) { - std::copy(std::begin(src.length), std::end(src.length), std::begin(dest->total)); - std::copy(std::begin(src.states), std::end(src.states), std::begin(dest->state)); + std::ranges::copy(src.length, std::begin(dest->total)); + std::ranges::copy(src.states, std::begin(dest->state)); } static void ConvertContext(const mbedtls_sha1_context& src, ShaDevice::ShaContext* dest) { - std::copy(std::begin(src.total), std::end(src.total), std::begin(dest->length)); - std::copy(std::begin(src.state), std::end(src.state), std::begin(dest->states)); + std::ranges::copy(src.total, std::begin(dest->length)); + std::ranges::copy(src.state, std::begin(dest->states)); } HLE::ReturnCode ShaDevice::ProcessShaCommand(ShaIoctlv command, const IOCtlVRequest& request) diff --git a/Source/Core/Core/IOS/ES/Formats.cpp b/Source/Core/Core/IOS/ES/Formats.cpp index 2826f7aed5..41f658f738 100644 --- a/Source/Core/Core/IOS/ES/Formats.cpp +++ b/Source/Core/Core/IOS/ES/Formats.cpp @@ -535,7 +535,7 @@ HLE::ReturnCode TicketReader::Unpersonalise(HLE::IOSC& iosc) sizeof(Ticket::title_key), key.data(), PID_ES); // Finally, IOS copies the decrypted title key back to the ticket buffer. if (ret == IPC_SUCCESS) - std::copy(key.cbegin(), key.cend(), ticket_begin + offsetof(Ticket, title_key)); + std::ranges::copy(key, ticket_begin + offsetof(Ticket, title_key)); return ret; } diff --git a/Source/Core/Core/IOS/ES/TitleManagement.cpp b/Source/Core/Core/IOS/ES/TitleManagement.cpp index 9ff28fc545..df74acd766 100644 --- a/Source/Core/Core/IOS/ES/TitleManagement.cpp +++ b/Source/Core/Core/IOS/ES/TitleManagement.cpp @@ -817,7 +817,7 @@ ReturnCode ESCore::ExportContentData(Context& context, u32 content_fd, u8* data, if (encrypt_ret != IPC_SUCCESS) return encrypt_ret; - std::copy(output.cbegin(), output.cend(), data); + std::ranges::copy(output, data); return IPC_SUCCESS; } diff --git a/Source/Core/Core/IOS/ES/Views.cpp b/Source/Core/Core/IOS/ES/Views.cpp index 71d03ea0ed..988e19d86c 100644 --- a/Source/Core/Core/IOS/ES/Views.cpp +++ b/Source/Core/Core/IOS/ES/Views.cpp @@ -147,7 +147,7 @@ ReturnCode ESCore::GetTicketFromView(const u8* ticket_view, u8* ticket, u32* tic return ES_EACCES; } - std::copy(ticket_bytes.begin(), ticket_bytes.end(), ticket); + std::ranges::copy(ticket_bytes, ticket); return IPC_SUCCESS; } diff --git a/Source/Core/Core/IOS/IOSC.cpp b/Source/Core/Core/IOS/IOSC.cpp index 357aee143e..703cc01443 100644 --- a/Source/Core/Core/IOS/IOSC.cpp +++ b/Source/Core/Core/IOS/IOSC.cpp @@ -551,7 +551,7 @@ void IOSC::Sign(u8* sig_out, u8* ap_cert_out, u64 title_id, const u8* data, u32 // Sign the data. const auto data_digest = Common::SHA1::CalculateDigest(data, data_size); const auto signature = Common::ec::Sign(ap_priv.data(), data_digest.data()); - std::copy(signature.cbegin(), signature.cend(), sig_out); + std::ranges::copy(signature, sig_out); } void IOSC::LoadDefaultEntries() diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp b/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp index b0be6bc249..0cca115ac5 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTEmu.cpp @@ -51,8 +51,8 @@ BluetoothEmuDevice::BluetoothEmuDevice(EmulationKernel& ios, const std::string& const bdaddr_t tmp_bd = {0x11, 0x02, 0x19, 0x79, 0, i}; // Previous records can be safely overwritten, since they are backed up - std::copy(tmp_bd.begin(), tmp_bd.end(), std::rbegin(bt_dinf.active[i].bdaddr)); - std::copy(tmp_bd.begin(), tmp_bd.end(), std::rbegin(bt_dinf.registered[i].bdaddr)); + std::ranges::copy(tmp_bd, std::rbegin(bt_dinf.active[i].bdaddr)); + std::ranges::copy(tmp_bd, std::rbegin(bt_dinf.registered[i].bdaddr)); const auto& wm_name = (i == WIIMOTE_BALANCE_BOARD) ? "Nintendo RVL-WBC-01" : "Nintendo RVL-CNT-01"; diff --git a/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp b/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp index 81b0e3c223..a0eaa58624 100644 --- a/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp +++ b/Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp @@ -482,9 +482,9 @@ bool BluetoothRealDevice::SendHCIStoreLinkKeyCommand() auto iterator = packet.begin() + sizeof(hci_cmd_hdr_t) + sizeof(hci_write_stored_link_key_cp); for (const auto& entry : m_link_keys) { - std::copy(entry.first.begin(), entry.first.end(), iterator); + std::ranges::copy(entry.first, iterator); iterator += entry.first.size(); - std::copy(entry.second.begin(), entry.second.end(), iterator); + std::ranges::copy(entry.second, iterator); iterator += entry.second.size(); } @@ -737,7 +737,7 @@ void BluetoothRealDevice::HandleBulkOrIntrTransfer(libusb_transfer* tr) hci_link_key_notification_ep notification; std::memcpy(¬ification, tr->buffer + sizeof(hci_event_hdr_t), sizeof(notification)); linkkey_t key; - std::copy(std::begin(notification.key), std::end(notification.key), std::begin(key)); + std::ranges::copy(notification.key, std::begin(key)); m_link_keys[notification.bdaddr] = key; } else if (event == HCI_EVENT_COMMAND_COMPL) diff --git a/Source/Core/Core/Movie.cpp b/Source/Core/Core/Movie.cpp index 325381f0e9..89e6d45d31 100644 --- a/Source/Core/Core/Movie.cpp +++ b/Source/Core/Core/Movie.cpp @@ -1100,7 +1100,7 @@ void MovieManager::LoadInput(const std::string& movie_path) "read-only mode off. Otherwise you'll probably get a desync.", byte_offset, byte_offset); - std::copy(movInput.begin(), movInput.end(), m_temp_input.begin()); + std::ranges::copy(movInput, m_temp_input.begin()); } else { diff --git a/Source/Core/Core/SysConf.cpp b/Source/Core/Core/SysConf.cpp index d9efcaa345..bc5f133f69 100644 --- a/Source/Core/Core/SysConf.cpp +++ b/Source/Core/Core/SysConf.cpp @@ -192,7 +192,7 @@ bool SysConf::Save() const // Make sure the buffer size is 0x4000 bytes now and write the footer. buffer.resize(SYSCONF_SIZE); constexpr std::array footer = {{'S', 'C', 'e', 'd'}}; - std::copy(footer.cbegin(), footer.cend(), buffer.end() - footer.size()); + std::ranges::copy(footer, buffer.end() - footer.size()); // Write the new data. const std::string temp_file = "/tmp/SYSCONF";