From 0de99b0006ce39d5b371f3d71fc299f2ef2e1955 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Sat, 16 Jun 2018 13:33:59 +0200 Subject: [PATCH] Stratosphere: Replace more raw loops with algorithms --- .../include/stratosphere/iserver.hpp | 3 ++- .../include/stratosphere/waitablemanager.hpp | 9 ++++----- .../libstratosphere/source/waitablemanager.cpp | 15 +++++---------- stratosphere/loader/source/ldr_launch_queue.cpp | 3 ++- stratosphere/loader/source/ldr_registration.cpp | 2 +- stratosphere/sm/source/sm_registration.cpp | 4 ++-- 6 files changed, 16 insertions(+), 20 deletions(-) diff --git a/stratosphere/libstratosphere/include/stratosphere/iserver.hpp b/stratosphere/libstratosphere/include/stratosphere/iserver.hpp index 24ff1ee67..06d140408 100644 --- a/stratosphere/libstratosphere/include/stratosphere/iserver.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/iserver.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include #include #include "iserviceobject.hpp" @@ -51,4 +52,4 @@ class IServer : public IWaitable { this->get_manager()->add_waitable(this->get_new_session(session_h)); return 0; } -}; \ No newline at end of file +}; diff --git a/stratosphere/libstratosphere/include/stratosphere/waitablemanager.hpp b/stratosphere/libstratosphere/include/stratosphere/waitablemanager.hpp index 5c0006e4a..13899697a 100644 --- a/stratosphere/libstratosphere/include/stratosphere/waitablemanager.hpp +++ b/stratosphere/libstratosphere/include/stratosphere/waitablemanager.hpp @@ -1,5 +1,7 @@ #pragma once #include +#include +#include #include #include "waitablemanagerbase.hpp" @@ -21,13 +23,10 @@ class WaitableManager : public WaitableManagerBase { WaitableManager(u64 t) : waitables(0), timeout(t), has_new_items(false) { } ~WaitableManager() override { /* This should call the destructor for every waitable. */ - for (auto & waitable : waitables) { - delete waitable; - } - waitables.clear(); + std::for_each(waitables.begin(), waitables.end(), std::default_delete{}); } virtual void add_waitable(IWaitable *waitable); virtual void process(); virtual void process_until_timeout(); -}; \ No newline at end of file +}; diff --git a/stratosphere/libstratosphere/source/waitablemanager.cpp b/stratosphere/libstratosphere/source/waitablemanager.cpp index fee21cb4b..89b899629 100644 --- a/stratosphere/libstratosphere/source/waitablemanager.cpp +++ b/stratosphere/libstratosphere/source/waitablemanager.cpp @@ -1,6 +1,7 @@ #include #include +#include #include @@ -43,14 +44,10 @@ void WaitableManager::process_internal(bool break_on_timeout) { rc = this->waitables[handle_index]->handle_signaled(0); - for (int i = 0; i < handle_index; i++) { - this->waitables[i]->update_priority(); - } + std::for_each(waitables.begin(), waitables.begin() + handle_index, std::mem_fn(&IWaitable::update_priority)); } else if (rc == 0xEA01) { /* Timeout. */ - for (auto & waitable : this->waitables) { - waitable->update_priority(); - } + std::for_each(waitables.begin(), waitables.end(), std::mem_fn(&IWaitable::update_priority)); if (break_on_timeout) { return; } @@ -72,9 +69,7 @@ void WaitableManager::process_internal(bool break_on_timeout) { /* Delete it. */ delete to_delete; - for (int i = 0; i < handle_index; i++) { - this->waitables[i]->update_priority(); - } + std::for_each(waitables.begin(), waitables.begin() + handle_index, std::mem_fn(&IWaitable::update_priority)); } /* Do deferred callback for each waitable. */ @@ -92,4 +87,4 @@ void WaitableManager::process() { void WaitableManager::process_until_timeout() { WaitableManager::process_internal(true); -} \ No newline at end of file +} diff --git a/stratosphere/loader/source/ldr_launch_queue.cpp b/stratosphere/loader/source/ldr_launch_queue.cpp index 53e3cd121..cf0cd4fc5 100644 --- a/stratosphere/loader/source/ldr_launch_queue.cpp +++ b/stratosphere/loader/source/ldr_launch_queue.cpp @@ -1,9 +1,10 @@ #include #include +#include #include #include "ldr_launch_queue.hpp" -static LaunchQueue::LaunchItem g_launch_queue[LAUNCH_QUEUE_SIZE] = {0}; +static std::array g_launch_queue = {0}; Result LaunchQueue::add(u64 tid, const char *args, u64 arg_size) { if(arg_size > LAUNCH_QUEUE_ARG_SIZE_MAX) { diff --git a/stratosphere/loader/source/ldr_registration.cpp b/stratosphere/loader/source/ldr_registration.cpp index 8b9853879..8a0d2a6ed 100644 --- a/stratosphere/loader/source/ldr_registration.cpp +++ b/stratosphere/loader/source/ldr_registration.cpp @@ -190,7 +190,7 @@ bool Registration::IsNroAlreadyLoaded(u64 index, u8 *build_id) { } for (unsigned int i = 0; i < NRO_INFO_MAX; i++) { - if (target_process->nro_infos[i].in_use && std::memcmp(target_process->nro_infos[i].build_id, build_id, 0x20) == 0) { + if (target_process->nro_infos[i].in_use && std::equal(build_id, build_id + 0x20, target_process->nro_infos[i].build_id)) { return true; } } diff --git a/stratosphere/sm/source/sm_registration.cpp b/stratosphere/sm/source/sm_registration.cpp index 46483a758..21ba9b674 100644 --- a/stratosphere/sm/source/sm_registration.cpp +++ b/stratosphere/sm/source/sm_registration.cpp @@ -3,8 +3,8 @@ #include #include "sm_registration.hpp" -static Registration::Process g_process_list[REGISTRATION_LIST_MAX_PROCESS] = {0}; -static Registration::Service g_service_list[REGISTRATION_LIST_MAX_SERVICE] = {0}; +static std::array g_process_list = {0}; +static std::array g_service_list = {0}; static u64 g_initial_process_id_low = 0; static u64 g_initial_process_id_high = 0;