diff --git a/libraries/libstratosphere/include/stratosphere/fs/fs_save_data_types.hpp b/libraries/libstratosphere/include/stratosphere/fs/fs_save_data_types.hpp index 4a1a91339..8d49efe3f 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/fs_save_data_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/fs_save_data_types.hpp @@ -127,30 +127,13 @@ namespace ams::fs { static_assert(std::is_trivially_destructible::value); constexpr inline bool operator<(const SaveDataAttribute &lhs, const SaveDataAttribute &rhs) { - #define FS_SDA_CHECK_FIELD(FIELD) \ - if (lhs.FIELD < rhs.FIELD) { \ - return true; \ - } else if (lhs.FIELD != rhs.FIELD) { \ - return false; \ - } - - FS_SDA_CHECK_FIELD(program_id); - FS_SDA_CHECK_FIELD(user_id); - FS_SDA_CHECK_FIELD(system_save_data_id); - FS_SDA_CHECK_FIELD(index); - FS_SDA_CHECK_FIELD(rank); - return false; - - #undef FS_SDA_CHECK_FIELD + return std::tie(lhs.program_id, lhs.user_id, lhs.system_save_data_id, lhs.index, lhs.rank) < + std::tie(rhs.program_id, rhs.user_id, rhs.system_save_data_id, rhs.index, rhs.rank); } constexpr inline bool operator==(const SaveDataAttribute &lhs, const SaveDataAttribute &rhs) { - return lhs.program_id == rhs.program_id && - lhs.user_id == rhs.user_id && - lhs.system_save_data_id == rhs.system_save_data_id && - lhs.type == rhs.type && - lhs.rank == rhs.rank && - lhs.index == rhs.index; + return std::tie(lhs.program_id, lhs.user_id, lhs.system_save_data_id, lhs.type, lhs.rank, lhs.index) == + std::tie(rhs.program_id, rhs.user_id, rhs.system_save_data_id, rhs.type, rhs.rank, rhs.index); } constexpr inline bool operator!=(const SaveDataAttribute &lhs, const SaveDataAttribute &rhs) { diff --git a/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta_key.hpp b/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta_key.hpp index 1ee1aa2f1..2b796d5b0 100644 --- a/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta_key.hpp +++ b/libraries/libstratosphere/include/stratosphere/ncm/ncm_content_meta_key.hpp @@ -34,37 +34,16 @@ namespace ams::ncm { ContentInstallType install_type; u8 padding[2]; - bool operator<(const ContentMetaKey& other) const { - if (this->id < other.id) { - return true; - } else if (this->id != other.id) { - return false; - } - - if (this->version < other.version) { - return true; - } else if (this->version != other.version) { - return false; - } - - if (this->type < other.type) { - return true; - } else if (this->type != other.type) { - return false; - } - - return this->install_type < other.install_type; + bool operator<(const ContentMetaKey& rhs) const { + return std::tie(this->id, this->version, this->type, this->install_type) < std::tie(rhs.id, rhs.version, rhs.type, rhs.install_type); } - constexpr bool operator==(const ContentMetaKey& other) const { - return this->id == other.id && - this->version == other.version && - this->type == other.type && - this->install_type == other.install_type; + constexpr bool operator==(const ContentMetaKey& rhs) const { + return std::tie(this->id, this->version, this->type, this->install_type) == std::tie(rhs.id, rhs.version, rhs.type, rhs.install_type); } - constexpr bool operator!=(const ContentMetaKey& other) const { - return !(*this == other); + constexpr bool operator!=(const ContentMetaKey& rhs) const { + return !(*this == rhs); } static constexpr ContentMetaKey MakeUnknownType(u64 id, u32 version) { diff --git a/libraries/libstratosphere/source/fs/fs_romfs_filesystem.cpp b/libraries/libstratosphere/source/fs/fs_romfs_filesystem.cpp index 824145ae8..78c22c7df 100644 --- a/libraries/libstratosphere/source/fs/fs_romfs_filesystem.cpp +++ b/libraries/libstratosphere/source/fs/fs_romfs_filesystem.cpp @@ -1,16 +1,12 @@ /* * Copyright (c) 2018-2020 Atmosphère-NX * - * This program is free software { - - } you can redistribute it and/or modify it + * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY { - - } without even the implied warranty of MERCHANTABILITY or + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * @@ -349,7 +345,7 @@ namespace ams::fs { return ResultSuccess(); } - Result RomFsFileSystem:: Initialize(IStorage *base, void *work, size_t work_size, bool use_cache) { + Result RomFsFileSystem::Initialize(IStorage *base, void *work, size_t work_size, bool use_cache) { AMS_ABORT_UNLESS(!use_cache || work != nullptr); AMS_ABORT_UNLESS(base != nullptr); diff --git a/libraries/libstratosphere/source/fs/fsa/fs_user_filesystem.cpp b/libraries/libstratosphere/source/fs/fsa/fs_user_filesystem.cpp index 1a10260a0..07129968e 100644 --- a/libraries/libstratosphere/source/fs/fsa/fs_user_filesystem.cpp +++ b/libraries/libstratosphere/source/fs/fsa/fs_user_filesystem.cpp @@ -1,18 +1,12 @@ /* * Copyright (c) 2018-2020 Atmosphère-NX * - * This program is free software { - - } - you can redistribute it and/or modify it + * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY { - - } - without even the implied warranty of MERCHANTABILITY or + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * diff --git a/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.cpp b/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.cpp index 8b643f2a9..19f7c6ffb 100644 --- a/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.cpp +++ b/libraries/libstratosphere/source/ncm/ncm_content_meta_database_impl.cpp @@ -110,8 +110,8 @@ namespace ams::ncm { size_t entries_written = 0; /* Iterate over all entries. */ - for (auto entry = this->kvs->begin(); entry != this->kvs->end(); entry++) { - const ContentMetaKey key = entry->GetKey(); + for (auto &entry : *this->kvs) { + const ContentMetaKey key = entry.GetKey(); /* Check if this entry matches the given filters. */ if (!((meta_type == ContentMetaType::Unknown || key.type == meta_type) && (min <= key.id && key.id <= max) && (install_type == ContentInstallType::Unknown || key.install_type == install_type))) { @@ -178,8 +178,8 @@ namespace ams::ncm { size_t entries_written = 0; /* Iterate over all entries. */ - for (auto entry = this->kvs->begin(); entry != this->kvs->end(); entry++) { - const ContentMetaKey key = entry->GetKey(); + for (auto &entry : *this->kvs) { + const ContentMetaKey key = entry.GetKey(); /* Check if this entry matches the given filters. */ if (!(type == ContentMetaType::Unknown || key.type == type)) { @@ -187,7 +187,7 @@ namespace ams::ncm { } /* Check if the entry has an application id. */ - ContentMetaReader reader(entry->GetValuePointer(), entry->GetValueSize()); + ContentMetaReader reader(entry.GetValuePointer(), entry.GetValueSize()); if (const auto entry_application_id = reader.GetApplicationId(key); entry_application_id) { /* Write the entry to the output buffer. */ @@ -315,12 +315,15 @@ namespace ams::ncm { return std::make_optional(i); } } + + /* TODO: C++20 (gcc 10) fixes ALWAYS_INLINE_LAMBDA in conjunction with trailing return types. */ + /* This should be changed to std::nullopt once possible. */ return std::optional(std::nullopt); }; /* Iterate over all entries. */ - for (auto entry = this->kvs->begin(); entry != this->kvs->end(); entry++) { - ContentMetaReader reader(entry->GetValuePointer(), entry->GetValueSize()); + for (auto &entry : *this->kvs) { + ContentMetaReader reader(entry.GetValuePointer(), entry.GetValueSize()); /* Check if any of this entry's content infos matches one of the content ids for lookup. */ /* If they do, then the content id isn't orphaned. */