Merge pull request #13090 from mitaclaw/ranges-modernization-1-trivial

Ranges Algorithms Modernization - Trivial
This commit is contained in:
JosJuice
2024-10-15 17:08:55 +02:00
committed by GitHub
52 changed files with 106 additions and 118 deletions
+2 -2
View File
@@ -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;
}
+2 -2
View File
@@ -97,7 +97,7 @@ std::vector<std::string> DoFileSearch(const std::vector<std::string>& directorie
// Remove duplicates (occurring because caller gave e.g. duplicate or overlapping directories -
// not because std::filesystem returns duplicates). Also note that this pathname-based uniqueness
// isn't as thorough as std::filesystem::equivalent.
std::sort(result.begin(), result.end());
std::ranges::sort(result);
result.erase(std::unique(result.begin(), result.end()), result.end());
// Dolphin expects to be able to use "/" (DIR_SEP) everywhere.
@@ -107,7 +107,7 @@ std::vector<std::string> DoFileSearch(const std::vector<std::string>& directorie
if constexpr (os_separator != DIR_SEP_CHR)
{
for (auto& path : result)
std::replace(path.begin(), path.end(), '\\', DIR_SEP_CHR);
std::ranges::replace(path, '\\', DIR_SEP_CHR);
}
return result;
+1 -1
View File
@@ -446,7 +446,7 @@ FSTEntry ScanDirectoryTree(std::string directory, bool recursive)
// about with directory separators (for host paths - emulated paths may require it) and instead
// use fs::path to interact with them.
auto wpath = path.wstring();
std::replace(wpath.begin(), wpath.end(), L'\\', L'/');
std::ranges::replace(wpath, L'\\', L'/');
return WStringToUTF8(wpath);
#else
return PathToString(path);
+2 -2
View File
@@ -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;
}
+5 -6
View File
@@ -234,8 +234,8 @@ std::string_view StripQuotes(std::string_view s)
// Turns "\n\rhello" into " hello".
void ReplaceBreaksWithSpaces(std::string& str)
{
std::replace(str.begin(), str.end(), '\r', ' ');
std::replace(str.begin(), str.end(), '\n', ' ');
std::ranges::replace(str, '\r', ' ');
std::ranges::replace(str, '\n', ' ');
}
void TruncateToCString(std::string* s)
@@ -403,8 +403,7 @@ void StringPopBackIf(std::string* s, char c)
size_t StringUTF8CodePointCount(std::string_view str)
{
return str.size() -
std::count_if(str.begin(), str.end(), [](char c) -> bool { return (c & 0xC0) == 0x80; });
return str.size() - std::ranges::count_if(str, [](char c) -> bool { return (c & 0xC0) == 0x80; });
}
#ifdef _WIN32
@@ -656,12 +655,12 @@ std::string GetEscapedHtml(std::string html)
void ToLower(std::string* str)
{
std::transform(str->begin(), str->end(), str->begin(), [](char c) { return Common::ToLower(c); });
std::ranges::transform(*str, str->begin(), static_cast<char (&)(char)>(Common::ToLower));
}
void ToUpper(std::string* str)
{
std::transform(str->begin(), str->end(), str->begin(), [](char c) { return Common::ToUpper(c); });
std::ranges::transform(*str, str->begin(), static_cast<char (&)(char)>(Common::ToUpper));
}
bool CaseInsensitiveEquals(std::string_view a, std::string_view b)
+1 -1
View File
@@ -265,7 +265,7 @@ struct SetGameMetadata
std::string executable_path = executable.path;
constexpr char BACKSLASH = '\\';
constexpr char FORWARDSLASH = '/';
std::replace(executable_path.begin(), executable_path.end(), BACKSLASH, FORWARDSLASH);
std::ranges::replace(executable_path, BACKSLASH, FORWARDSLASH);
config->SetRunningGameMetadata(SConfig::MakeGameID(PathToFileName(executable_path)));
Host_TitleChanged();
+6 -6
View File
@@ -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()
+1 -1
View File
@@ -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()
+1 -2
View File
@@ -307,8 +307,7 @@ void BranchWatch::UpdateHitsSnapshot()
void BranchWatch::ClearSelectionInspection()
{
std::for_each(m_selection.begin(), m_selection.end(),
[](Selection::value_type& value) { value.inspection = {}; });
std::ranges::for_each(m_selection, [](Selection::value_type& value) { value.inspection = {}; });
}
void BranchWatch::SetSelectedInspected(std::size_t idx, SelectionInspection inspection)
@@ -266,7 +266,7 @@ Common::Debug::Threads PPCDebugInterface::GetThreads(const Core::CPUThreadGuard&
const u32 prev_addr = active_thread->Data().thread_link.prev;
insert_threads(prev_addr, [](const auto& thread) { return thread.Data().thread_link.prev; });
std::reverse(threads.begin(), threads.end());
std::ranges::reverse(threads);
const u32 next_addr = active_thread->Data().thread_link.next;
threads.emplace_back(std::move(active_thread));
+1 -1
View File
@@ -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)
+2 -2
View File
@@ -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());
+1 -1
View File
@@ -93,7 +93,7 @@ int CSIDevice_GBAEmu::RunBuffer(u8* buffer, int request_length)
std::vector<u8> 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 =
+1 -1
View File
@@ -422,7 +422,7 @@ public:
if (data)
{
std::vector<u8> 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()))
+1 -1
View File
@@ -70,7 +70,7 @@ CameraLogic::GetCameraPoints(const Common::Matrix44& transform, Common::Vec2 fie
std::array<CameraPoint, CameraLogic::NUM_POINTS> camera_points;
std::transform(leds.begin(), leds.end(), camera_points.begin(), [&](const Vec3& v) {
std::ranges::transform(leds, camera_points.begin(), [&](const Vec3& v) {
const auto point = camera_view * Vec4(v, 1.0);
// Check if LED is behind camera.
@@ -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;
@@ -44,7 +44,7 @@ struct MPI : mbedtls_mpi
if (mbedtls_mpi_write_binary(this, out_data->data(), out_data->size()))
return false;
std::reverse(out_data->begin(), out_data->end());
std::ranges::reverse(*out_data);
return true;
}
+4 -4
View File
@@ -33,14 +33,14 @@ std::optional<IPCReply> 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)
+1 -1
View File
@@ -530,7 +530,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;
}
+4 -5
View File
@@ -219,11 +219,10 @@ ESCore::GetStoredContentsFromTMD(const ES::TMDReader& tmd,
u32 ESCore::GetSharedContentsCount() const
{
const auto entries = m_ios.GetFS()->ReadDirectory(PID_KERNEL, PID_KERNEL, "/shared1");
return static_cast<u32>(
std::count_if(entries->begin(), entries->end(), [this](const std::string& entry) {
return !m_ios.GetFS()->ReadDirectory(PID_KERNEL, PID_KERNEL, "/shared1/" + entry) &&
entry.size() == 12 && entry.compare(8, 4, ".app") == 0;
}));
return static_cast<u32>(std::ranges::count_if(*entries, [this](const std::string& entry) {
return !m_ios.GetFS()->ReadDirectory(PID_KERNEL, PID_KERNEL, "/shared1/" + entry) &&
entry.size() == 12 && entry.compare(8, 4, ".app") == 0;
}));
}
std::vector<std::array<u8, 20>> ESCore::GetSharedContents() const

Some files were not shown because too many files have changed in this diff Show More