VolumeVerifier.cpp: Use arrays of string_view objects instead of strings.

string_view is a thin wrapper around C strings, so it's more efficient
for constant strings than C++ strings.

The unordered_set<> also adds extra runtime overhead. For small arrays,
a simple linear search works. For larger arrays, std::binary_search()
works better than linear but without the unordered_set<> overhead.

ShouldBeDualLayer(): Removed a duplicate "SK8X52" entry.
This commit is contained in:
David Korth 2019-09-24 00:19:22 -04:00
parent 084344aa5d
commit d660aba20f
1 changed files with 18 additions and 11 deletions

View File

@ -678,38 +678,45 @@ bool VolumeVerifier::IsDebugSigned() const
bool VolumeVerifier::ShouldHaveChannelPartition() const
{
const std::unordered_set<std::string> channel_discs{
static constexpr std::array<std::string_view, 18> channel_discs = {
"RFNE01", "RFNJ01", "RFNK01", "RFNP01", "RFNW01", "RFPE01", "RFPJ01", "RFPK01", "RFPP01",
"RFPW01", "RGWE41", "RGWJ41", "RGWP41", "RGWX41", "RMCE01", "RMCJ01", "RMCK01", "RMCP01",
};
return channel_discs.find(m_volume.GetGameID()) != channel_discs.end();
return std::binary_search(channel_discs.cbegin(), channel_discs.cend(),
std::string_view(m_volume.GetGameID()));
}
bool VolumeVerifier::ShouldHaveInstallPartition() const
{
const std::unordered_set<std::string> dragon_quest_x{"S4MJGD", "S4SJGD", "S6TJGD", "SDQJGD"};
return dragon_quest_x.find(m_volume.GetGameID()) != dragon_quest_x.end();
static constexpr std::array<std::string_view, 4> dragon_quest_x = {"S4MJGD", "S4SJGD", "S6TJGD",
"SDQJGD"};
const std::string& game_id = m_volume.GetGameID();
return std::any_of(dragon_quest_x.cbegin(), dragon_quest_x.cend(),
[&game_id](std::string_view x) { return x == game_id; });
}
bool VolumeVerifier::ShouldHaveMasterpiecePartitions() const
{
const std::unordered_set<std::string> ssbb{"RSBE01", "RSBJ01", "RSBK01", "RSBP01"};
return ssbb.find(m_volume.GetGameID()) != ssbb.end();
static constexpr std::array<std::string_view, 4> ssbb = {"RSBE01", "RSBJ01", "RSBK01", "RSBP01"};
const std::string& game_id = m_volume.GetGameID();
return std::any_of(ssbb.cbegin(), ssbb.cend(),
[&game_id](std::string_view x) { return x == game_id; });
}
bool VolumeVerifier::ShouldBeDualLayer() const
{
// The Japanese versions of Xenoblade and The Last Story are single-layer
// (unlike the other versions) and must not be added to this list.
const std::unordered_set<std::string> dual_layer_discs{
static constexpr std::array<std::string_view, 33> dual_layer_discs = {
"R3ME01", "R3MP01", "R3OE01", "R3OJ01", "R3OP01", "RSBE01", "RSBJ01", "RSBK01", "RSBP01",
"RXMJ8P", "S59E01", "S59JC8", "S59P01", "S5QJC8", "SK8X52", "SAKENS", "SAKPNS", "SK8V52",
"SK8X52", "SLSEXJ", "SLSP01", "SQIE4Q", "SQIP4Q", "SQIY4Q", "SR5E41", "SR5P41", "SUOE41",
"SUOP41", "SVXX52", "SVXY52", "SX4E01", "SX4P01", "SZ3EGT", "SZ3PGT",
"RXMJ8P", "S59E01", "S59JC8", "S59P01", "S5QJC8", "SAKENS", "SAKPNS", "SK8V52", "SK8X52",
"SLSEXJ", "SLSP01", "SQIE4Q", "SQIP4Q", "SQIY4Q", "SR5E41", "SR5P41", "SUOE41", "SUOP41",
"SVXX52", "SVXY52", "SX4E01", "SX4P01", "SZ3EGT", "SZ3PGT",
};
return dual_layer_discs.find(m_volume.GetGameID()) != dual_layer_discs.end();
return std::binary_search(dual_layer_discs.cbegin(), dual_layer_discs.cend(),
std::string_view(m_volume.GetGameID()));
}
void VolumeVerifier::CheckDiscSize()