Stratosphere: Replace more raw loops with algorithms

This commit is contained in:
Tony Wasserka 2018-06-16 13:33:59 +02:00
parent c10dca48fe
commit 0de99b0006
6 changed files with 16 additions and 20 deletions

View File

@ -1,5 +1,6 @@
#pragma once
#include <switch.h>
#include <algorithm>
#include <type_traits>
#include "iserviceobject.hpp"

View File

@ -1,5 +1,7 @@
#pragma once
#include <switch.h>
#include <algorithm>
#include <memory>
#include <vector>
#include "waitablemanagerbase.hpp"
@ -21,10 +23,7 @@ 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<IWaitable>{});
}
virtual void add_waitable(IWaitable *waitable);

View File

@ -1,6 +1,7 @@
#include <switch.h>
#include <algorithm>
#include <functional>
#include <stratosphere/waitablemanager.hpp>
@ -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. */

View File

@ -1,9 +1,10 @@
#include <switch.h>
#include <algorithm>
#include <array>
#include <cstdio>
#include "ldr_launch_queue.hpp"
static LaunchQueue::LaunchItem g_launch_queue[LAUNCH_QUEUE_SIZE] = {0};
static std::array<LaunchQueue::LaunchItem, LAUNCH_QUEUE_SIZE> g_launch_queue = {0};
Result LaunchQueue::add(u64 tid, const char *args, u64 arg_size) {
if(arg_size > LAUNCH_QUEUE_ARG_SIZE_MAX) {

View File

@ -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;
}
}

View File

@ -3,8 +3,8 @@
#include <stratosphere/servicesession.hpp>
#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<Registration::Process, REGISTRATION_LIST_MAX_PROCESS> g_process_list = {0};
static std::array<Registration::Service, REGISTRATION_LIST_MAX_SERVICE> g_service_list = {0};
static u64 g_initial_process_id_low = 0;
static u64 g_initial_process_id_high = 0;