mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-04-22 12:34:47 +00:00
ncm: address some review suggestions (thanks @leoetlino!)
This commit is contained in:
parent
62e9b91c08
commit
1fbaaa3c18
5 changed files with 25 additions and 70 deletions
|
@ -127,30 +127,13 @@ namespace ams::fs {
|
|||
static_assert(std::is_trivially_destructible<SaveDataAttribute>::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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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<size_t>(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. */
|
||||
|
|
Loading…
Add table
Reference in a new issue