From 999498c0a04d52d4d857742b78f13d3415ba246a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Fri, 4 May 2018 01:24:34 +0200 Subject: [PATCH] =?UTF-8?q?Stratosph=C3=A8re:=20Simplify=20some=20for=20lo?= =?UTF-8?q?ops=20(#76)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Simplifies some loops by removing the need to manually calculate or re-specify the array size. Eliminates any chance of using the wrong size and less typing. --- stratosphere/boot2/source/boot2_main.cpp | 8 ++++---- stratosphere/loader/source/ldr_launch_queue.cpp | 2 +- stratosphere/sm/source/sm_registration.cpp | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/stratosphere/boot2/source/boot2_main.cpp b/stratosphere/boot2/source/boot2_main.cpp index 1c290701f..704a36751 100644 --- a/stratosphere/boot2/source/boot2_main.cpp +++ b/stratosphere/boot2/source/boot2_main.cpp @@ -151,11 +151,11 @@ int main(int argc, char **argv) LaunchTitle(0x0100000000000007, 3, 0, NULL); bool maintenance = ShouldForceMaintenanceMode(); - for (unsigned int i = 0; i < sizeof(g_additional_launch_programs) / sizeof(g_additional_launch_programs[0]); i++) { - if (!maintenance || std::get(g_additional_launch_programs[i])) { - LaunchTitle(std::get(g_additional_launch_programs[i]), 3, 0, NULL); + for (auto &launch_program : g_additional_launch_programs) { + if (!maintenance || std::get(launch_program)) { + LaunchTitle(std::get(launch_program), 3, 0, NULL); } } return 0; -} \ 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 94df49965..cbca94b02 100644 --- a/stratosphere/loader/source/ldr_launch_queue.cpp +++ b/stratosphere/loader/source/ldr_launch_queue.cpp @@ -79,4 +79,4 @@ LaunchQueue::LaunchItem *LaunchQueue::get_item(u64 tid) { return NULL; } return &g_launch_queue[idx]; -} \ No newline at end of file +} diff --git a/stratosphere/sm/source/sm_registration.cpp b/stratosphere/sm/source/sm_registration.cpp index 714ca42b8..15a25719f 100644 --- a/stratosphere/sm/source/sm_registration.cpp +++ b/stratosphere/sm/source/sm_registration.cpp @@ -21,9 +21,9 @@ u64 GetServiceNameLength(u64 service) { /* Utilities. */ Registration::Process *Registration::GetProcessForPid(u64 pid) { - for (unsigned int i = 0; i < REGISTRATION_LIST_MAX_PROCESS; i++) { - if (g_process_list[i].pid == pid) { - return &g_process_list[i]; + for (auto &process : g_process_list) { + if (process.pid == pid) { + return &process; } } return NULL; @@ -33,10 +33,10 @@ Registration::Process *Registration::GetFreeProcess() { return GetProcessForPid(0); } -Registration::Service *Registration::GetService(u64 service) { - for (unsigned int i = 0; i < REGISTRATION_LIST_MAX_SERVICE; i++) { - if (g_service_list[i].service_name == service) { - return &g_service_list[i]; +Registration::Service *Registration::GetService(u64 service_name) { + for (auto &service : g_service_list) { + if (service.service_name == service_name) { + return &service; } } return NULL;