mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-14 15:14:23 -04:00
Modernize C++ usage (#144)
* Stratosphere: Use modern C++ idioms in some places * algorithms like std::for_each are used instead of raw loops * Stratosphere: Replace more raw loops with algorithms * Stratosphere: Add a utility predicate function to test for equality with a reference element This can be used to rewrite some common raw loops using algorithms instead * fs.mitm: Use variant * fs.mitm: Use enum class * fs.mitm: Turn RomFSSourceInfo::Cleanup into a destructor This obsoletes the need for a custom deleter in other places * fs.mitm: Use enum class some more * fs.mitm: Use unique_ptr * fs.mitm: Simplify initialization * Stratosphere: Simplify initialization * fs.mitm: Use unique_ptr (fix memory leak along the way) The previous code was using "delete" rather than "delete[]" * fs.mitm: Use vector::emplace_back rather than push_back emplace_back constructs elements in-place, hence avoiding a redundant element copy. * Stratosphere: Replace more raw loops with algorithms * Stratosphere: Use unique_ptr * fs.mitm: Replace more raw loops with algorithms * Stratosphere: Prefer move-construction over copy-construction when moving sink parameters around
This commit is contained in:
parent
f1c326aec3
commit
ad636f7216
28 changed files with 353 additions and 374 deletions
|
@ -1,9 +1,11 @@
|
|||
#include <switch.h>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdio>
|
||||
#include "ldr_launch_queue.hpp"
|
||||
#include "meta_tools.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) {
|
||||
|
@ -45,12 +47,11 @@ Result LaunchQueue::add_item(const LaunchItem *item) {
|
|||
}
|
||||
|
||||
int LaunchQueue::get_index(u64 tid) {
|
||||
for(unsigned int i = 0; i < LAUNCH_QUEUE_SIZE; i++) {
|
||||
if(g_launch_queue[i].tid == tid) {
|
||||
return i;
|
||||
}
|
||||
auto it = std::find_if(g_launch_queue.begin(), g_launch_queue.end(), member_equals_fn(&LaunchQueue::LaunchItem::tid, tid));
|
||||
if (it == g_launch_queue.end()) {
|
||||
return LAUNCH_QUEUE_FULL;
|
||||
}
|
||||
return LAUNCH_QUEUE_FULL;
|
||||
return std::distance(g_launch_queue.begin(), it);
|
||||
}
|
||||
|
||||
int LaunchQueue::get_free_index(u64 tid) {
|
||||
|
@ -74,8 +75,8 @@ void LaunchQueue::clear() {
|
|||
|
||||
|
||||
LaunchQueue::LaunchItem *LaunchQueue::get_item(u64 tid) {
|
||||
int idx;
|
||||
if ((idx = get_index(tid)) == LAUNCH_QUEUE_FULL) {
|
||||
int idx = get_index(tid);
|
||||
if (idx == LAUNCH_QUEUE_FULL) {
|
||||
return NULL;
|
||||
}
|
||||
return &g_launch_queue[idx];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue