ncm: address some review suggestions (thanks @leoetlino!)

This commit is contained in:
Michael Scire 2020-03-07 20:01:14 -08:00
parent 62e9b91c08
commit 1fbaaa3c18
5 changed files with 25 additions and 70 deletions

View File

@ -127,30 +127,13 @@ namespace ams::fs {
static_assert(std::is_trivially_destructible<SaveDataAttribute>::value); static_assert(std::is_trivially_destructible<SaveDataAttribute>::value);
constexpr inline bool operator<(const SaveDataAttribute &lhs, const SaveDataAttribute &rhs) { constexpr inline bool operator<(const SaveDataAttribute &lhs, const SaveDataAttribute &rhs) {
#define FS_SDA_CHECK_FIELD(FIELD) \ return std::tie(lhs.program_id, lhs.user_id, lhs.system_save_data_id, lhs.index, lhs.rank) <
if (lhs.FIELD < rhs.FIELD) { \ std::tie(rhs.program_id, rhs.user_id, rhs.system_save_data_id, rhs.index, rhs.rank);
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
} }
constexpr inline bool operator==(const SaveDataAttribute &lhs, const SaveDataAttribute &rhs) { constexpr inline bool operator==(const SaveDataAttribute &lhs, const SaveDataAttribute &rhs) {
return lhs.program_id == rhs.program_id && return std::tie(lhs.program_id, lhs.user_id, lhs.system_save_data_id, lhs.type, lhs.rank, lhs.index) ==
lhs.user_id == rhs.user_id && std::tie(rhs.program_id, rhs.user_id, rhs.system_save_data_id, rhs.type, rhs.rank, rhs.index);
lhs.system_save_data_id == rhs.system_save_data_id &&
lhs.type == rhs.type &&
lhs.rank == rhs.rank &&
lhs.index == rhs.index;
} }
constexpr inline bool operator!=(const SaveDataAttribute &lhs, const SaveDataAttribute &rhs) { constexpr inline bool operator!=(const SaveDataAttribute &lhs, const SaveDataAttribute &rhs) {

View File

@ -34,37 +34,16 @@ namespace ams::ncm {
ContentInstallType install_type; ContentInstallType install_type;
u8 padding[2]; u8 padding[2];
bool operator<(const ContentMetaKey& other) const { bool operator<(const ContentMetaKey& rhs) const {
if (this->id < other.id) { return std::tie(this->id, this->version, this->type, this->install_type) < std::tie(rhs.id, rhs.version, rhs.type, rhs.install_type);
return true;
} else if (this->id != other.id) {
return false;
} }
if (this->version < other.version) { constexpr bool operator==(const ContentMetaKey& rhs) const {
return true; return std::tie(this->id, this->version, this->type, this->install_type) == std::tie(rhs.id, rhs.version, rhs.type, rhs.install_type);
} else if (this->version != other.version) {
return false;
} }
if (this->type < other.type) { constexpr bool operator!=(const ContentMetaKey& rhs) const {
return true; return !(*this == rhs);
} else if (this->type != other.type) {
return false;
}
return this->install_type < other.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& other) const {
return !(*this == other);
} }
static constexpr ContentMetaKey MakeUnknownType(u64 id, u32 version) { static constexpr ContentMetaKey MakeUnknownType(u64 id, u32 version) {

View File

@ -1,16 +1,12 @@
/* /*
* Copyright (c) 2018-2020 Atmosphère-NX * Copyright (c) 2018-2020 Atmosphère-NX
* *
* This program is free software { * This program is free software; you can redistribute it and/or modify it
} you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License, * under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation. * version 2, as published by the Free Software Foundation.
* *
* This program is distributed in the hope it will be useful, but WITHOUT * This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY { * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
} without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
@ -349,7 +345,7 @@ namespace ams::fs {
return ResultSuccess(); 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(!use_cache || work != nullptr);
AMS_ABORT_UNLESS(base != nullptr); AMS_ABORT_UNLESS(base != nullptr);

View File

@ -1,18 +1,12 @@
/* /*
* Copyright (c) 2018-2020 Atmosphère-NX * Copyright (c) 2018-2020 Atmosphère-NX
* *
* This program is free software { * This program is free software; you can redistribute it and/or modify it
}
you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License, * under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation. * version 2, as published by the Free Software Foundation.
* *
* This program is distributed in the hope it will be useful, but WITHOUT * This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY { * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
}
without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *

View File

@ -110,8 +110,8 @@ namespace ams::ncm {
size_t entries_written = 0; size_t entries_written = 0;
/* Iterate over all entries. */ /* Iterate over all entries. */
for (auto entry = this->kvs->begin(); entry != this->kvs->end(); entry++) { for (auto &entry : *this->kvs) {
const ContentMetaKey key = entry->GetKey(); const ContentMetaKey key = entry.GetKey();
/* Check if this entry matches the given filters. */ /* 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))) { 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; size_t entries_written = 0;
/* Iterate over all entries. */ /* Iterate over all entries. */
for (auto entry = this->kvs->begin(); entry != this->kvs->end(); entry++) { for (auto &entry : *this->kvs) {
const ContentMetaKey key = entry->GetKey(); const ContentMetaKey key = entry.GetKey();
/* Check if this entry matches the given filters. */ /* Check if this entry matches the given filters. */
if (!(type == ContentMetaType::Unknown || key.type == type)) { if (!(type == ContentMetaType::Unknown || key.type == type)) {
@ -187,7 +187,7 @@ namespace ams::ncm {
} }
/* Check if the entry has an application id. */ /* 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) { if (const auto entry_application_id = reader.GetApplicationId(key); entry_application_id) {
/* Write the entry to the output buffer. */ /* Write the entry to the output buffer. */
@ -315,12 +315,15 @@ namespace ams::ncm {
return std::make_optional(i); 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<size_t>(std::nullopt); return std::optional<size_t>(std::nullopt);
}; };
/* Iterate over all entries. */ /* Iterate over all entries. */
for (auto entry = this->kvs->begin(); entry != this->kvs->end(); entry++) { for (auto &entry : *this->kvs) {
ContentMetaReader reader(entry->GetValuePointer(), entry->GetValueSize()); ContentMetaReader reader(entry.GetValuePointer(), entry.GetValueSize());
/* Check if any of this entry's content infos matches one of the content ids for lookup. */ /* 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. */ /* If they do, then the content id isn't orphaned. */