diff options
| author | David Korth <gerbilsoft@gerbilsoft.com> | 2019-09-24 00:19:22 -0400 |
|---|---|---|
| committer | David Korth <gerbilsoft@gerbilsoft.com> | 2019-12-29 23:42:55 -0500 |
| commit | d660aba20fae070a51e01936aa32044d31a96df7 (patch) | |
| tree | a7d171fc1590506ca5df2888274d741458e313da /Source/Core/DiscIO/VolumeVerifier.cpp | |
| parent | 084344aa5d9a39fc05cfe952005e530766c3c29c (diff) | |
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.
Diffstat (limited to 'Source/Core/DiscIO/VolumeVerifier.cpp')
| -rw-r--r-- | Source/Core/DiscIO/VolumeVerifier.cpp | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/Source/Core/DiscIO/VolumeVerifier.cpp b/Source/Core/DiscIO/VolumeVerifier.cpp index 905a1cc26d..0634e34b66 100644 --- a/Source/Core/DiscIO/VolumeVerifier.cpp +++ b/Source/Core/DiscIO/VolumeVerifier.cpp @@ -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() |
