From 8f059ae3982c5b6a1ae9d313ea4229563328423c Mon Sep 17 00:00:00 2001 From: Hamish Milne Date: Sun, 29 Mar 2020 11:39:46 +0100 Subject: [PATCH] Apply suggestions from code review Co-Authored-By: Mat M. --- src/common/archives.h | 2 +- src/common/memory_ref.h | 4 ++-- src/common/serialization/boost_flat_set.h | 2 +- src/common/thread_queue_list.h | 6 +++--- src/core/arm/arm_interface.h | 18 +++++++++--------- src/core/hle/kernel/config_mem.h | 2 +- src/core/hle/kernel/hle_ipc.cpp | 4 ++-- src/core/hle/kernel/kernel.cpp | 3 ++- src/core/hle/kernel/svc.cpp | 4 ++-- 9 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/common/archives.h b/src/common/archives.h index 993128197..4f8b735d3 100644 --- a/src/common/archives.h +++ b/src/common/archives.h @@ -4,7 +4,7 @@ #pragma once -#include "boost/archive/binary_iarchive.hpp" +#include #include "boost/archive/binary_oarchive.hpp" #include "boost/serialization/export.hpp" diff --git a/src/common/memory_ref.h b/src/common/memory_ref.h index f1a3286ab..65946fc58 100644 --- a/src/common/memory_ref.h +++ b/src/common/memory_ref.h @@ -29,7 +29,7 @@ private: class BufferMem : public BackingMem { public: BufferMem() = default; - BufferMem(u32 size) : data(std::vector(size)) {} + explicit BufferMem(std::size_t size) : data(size) {} u8* GetPtr() override { return data.data(); @@ -77,7 +77,7 @@ public: inline u8* GetPtr() { return cptr; } - inline operator bool() const { + explicit operator bool() const { return cptr != nullptr; } inline const u8* GetPtr() const { diff --git a/src/common/serialization/boost_flat_set.h b/src/common/serialization/boost_flat_set.h index 7fe0fe097..c47e8c1a7 100644 --- a/src/common/serialization/boost_flat_set.h +++ b/src/common/serialization/boost_flat_set.h @@ -19,7 +19,7 @@ void load(Archive& ar, boost::container::flat_set& set, const unsigned int fi u64 count{}; ar >> count; set.clear(); - for (auto i = 0; i < count; i++) { + for (u64 i = 0; i < count; i++) { T value{}; ar >> value; set.insert(value); diff --git a/src/common/thread_queue_list.h b/src/common/thread_queue_list.h index c25bbe585..abeb465ad 100644 --- a/src/common/thread_queue_list.h +++ b/src/common/thread_queue_list.h @@ -167,7 +167,7 @@ private: } else if (q == UnlinkedTag()) { return -1; } else { - return static_cast(q - &queues[0]); + return q - queues.data(); } } @@ -186,8 +186,8 @@ private: void save(Archive& ar, const unsigned int file_version) const { s32 idx = ToIndex(first); ar << idx; - for (auto i = 0; i < NUM_QUEUES; i++) { - s32 idx1 = ToIndex(queues[i].next_nonempty); + for (size_t i = 0; i < NUM_QUEUES; i++) { + const s32 idx1 = ToIndex(queues[i].next_nonempty); ar << idx1; ar << queues[i].data; } diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h index b02e3941f..e39e1b9fa 100644 --- a/src/core/arm/arm_interface.h +++ b/src/core/arm/arm_interface.h @@ -28,12 +28,12 @@ public: template void save(Archive& ar, const unsigned int file_version) const { - for (auto i = 0; i < 16; i++) { - auto r = GetCpuRegister(i); + for (size_t i = 0; i < 16; i++) { + const auto r = GetCpuRegister(i); ar << r; } - for (auto i = 0; i < 16; i++) { - auto r = GetFpuRegister(i); + for (size_t i = 0; i < 16; i++) { + const auto r = GetFpuRegister(i); ar << r; } auto r1 = GetCpsr(); @@ -47,11 +47,11 @@ public: template void load(Archive& ar, const unsigned int file_version) { u32 r; - for (auto i = 0; i < 16; i++) { + for (size_t i = 0; i < 16; i++) { ar >> r; SetCpuRegister(i, r); } - for (auto i = 0; i < 16; i++) { + for (size_t i = 0; i < 16; i++) { ar >> r; SetFpuRegister(i, r); } @@ -247,7 +247,7 @@ private: ar << id; auto page_table = GetPageTable(); ar << page_table; - for (auto i = 0; i < 15; i++) { + for (size_t i = 0; i < 15; i++) { auto r = GetReg(i); ar << r; } @@ -255,7 +255,7 @@ private: ar << pc; auto cpsr = GetCPSR(); ar << cpsr; - for (auto i = 0; i < 32; i++) { + for (size_t i = 0; i < 32; i++) { auto r = GetVFPReg(i); ar << r; } @@ -278,7 +278,7 @@ private: ar >> page_table; SetPageTable(page_table); u32 r; - for (auto i = 0; i < 15; i++) { + for (size_t = 0; i < 15; i++) { ar >> r; SetReg(i, r); } diff --git a/src/core/hle/kernel/config_mem.h b/src/core/hle/kernel/config_mem.h index c466345ec..a81a5d291 100644 --- a/src/core/hle/kernel/config_mem.h +++ b/src/core/hle/kernel/config_mem.h @@ -58,7 +58,7 @@ public: ConfigMemDef& GetConfigMem(); u8* GetPtr() override { - return static_cast(static_cast(&config_mem)); + return reinterpret_cast(&config_mem)); } u32 GetSize() const override { diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index 23f577490..88bd6b71b 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp @@ -21,7 +21,7 @@ class HLERequestContext::ThreadCallback : public Kernel::WakeupCallback { public: ThreadCallback(std::shared_ptr context_, std::shared_ptr callback_) - : context(context_), callback(callback_) {} + : context(std::move(context_)), callback(std::move(callback_)) {} void WakeUp(ThreadWakeupReason reason, std::shared_ptr thread, std::shared_ptr object) { ASSERT(thread->status == ThreadStatus::WaitHleEvent); @@ -296,7 +296,7 @@ MappedBuffer::MappedBuffer() : memory(&Core::Global().Memory()) {} MappedBuffer::MappedBuffer(Memory::MemorySystem& memory, std::shared_ptr process, u32 descriptor, VAddr address, u32 id) - : memory(&memory), id(id), address(address), process(process) { + : memory(&memory), id(id), address(address), process(std::move(process)) { IPC::MappedBufferDescInfo desc{descriptor}; size = desc.size; perms = desc.perms; diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 8afddb499..11ef90771 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -24,7 +24,8 @@ KernelSystem::KernelSystem(Memory::MemorySystem& memory, Core::Timing& timing, u32 num_cores, u8 n3ds_mode) : memory(memory), timing(timing), prepare_reschedule_callback(std::move(prepare_reschedule_callback)) { - for (auto i = 0; i < memory_regions.size(); i++) { +std::generate(memory_regions.begin(), memory_regions.end(), + [] { return std::make_shared(); }); memory_regions[i] = std::make_shared(); } MemoryInit(system_mode, n3ds_mode); diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 9aeeea236..8f1ba5e01 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -409,7 +409,7 @@ static ResultCode ReceiveIPCRequest(Kernel::KernelSystem& kernel, Memory::Memory class SVC_SyncCallback : public Kernel::WakeupCallback { public: - SVC_SyncCallback(bool do_output_) : do_output(do_output_) {} + explicit SVC_SyncCallback(bool do_output_) : do_output(do_output_) {} void WakeUp(ThreadWakeupReason reason, std::shared_ptr thread, std::shared_ptr object) { @@ -442,7 +442,7 @@ private: class SVC_IPCCallback : public Kernel::WakeupCallback { public: - SVC_IPCCallback(Core::System& system_) : system(system_) {} + explicit SVC_IPCCallback(Core::System& system_) : system(system_) {} void WakeUp(ThreadWakeupReason reason, std::shared_ptr thread, std::shared_ptr object) {