Common: Drop fallback path for HeterogeneousContainers

This commit is contained in:
Stenzek 2023-09-05 21:03:49 +10:00
parent 58b4946fb9
commit 391307efaa
6 changed files with 74 additions and 162 deletions

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
/**
@ -47,8 +47,6 @@ struct transparent_string_less
};
} // namespace detail
// This requires C++20, so fallback to ugly heap allocations if we don't have it.
#if __cplusplus >= 202002L
template<typename ValueType>
using UnorderedStringMap =
std::unordered_map<std::string, ValueType, detail::transparent_string_hash, detail::transparent_string_equal>;
@ -60,92 +58,6 @@ using UnorderedStringSet =
using UnorderedStringMultiSet =
std::unordered_multiset<std::string, detail::transparent_string_hash, detail::transparent_string_equal>;
template<typename KeyType, typename ValueType>
ALWAYS_INLINE typename UnorderedStringMap<ValueType>::const_iterator
UnorderedStringMapFind(const UnorderedStringMap<ValueType>& map, const KeyType& key)
{
return map.find(key);
}
template<typename KeyType, typename ValueType>
ALWAYS_INLINE typename UnorderedStringMap<ValueType>::iterator
UnorderedStringMapFind(UnorderedStringMap<ValueType>& map, const KeyType& key)
{
return map.find(key);
}
template<typename KeyType, typename ValueType>
ALWAYS_INLINE typename UnorderedStringMultimap<ValueType>::const_iterator
UnorderedStringMultiMapFind(const UnorderedStringMultimap<ValueType>& map, const KeyType& key)
{
return map.find(key);
}
template<typename KeyType, typename ValueType>
ALWAYS_INLINE std::pair<typename UnorderedStringMultimap<ValueType>::const_iterator,
typename UnorderedStringMultimap<ValueType>::const_iterator>
UnorderedStringMultiMapEqualRange(const UnorderedStringMultimap<ValueType>& map, const KeyType& key)
{
return map.equal_range(key);
}
template<typename KeyType, typename ValueType>
ALWAYS_INLINE typename UnorderedStringMultimap<ValueType>::iterator
UnorderedStringMultiMapFind(UnorderedStringMultimap<ValueType>& map, const KeyType& key)
{
return map.find(key);
}
template<typename KeyType, typename ValueType>
ALWAYS_INLINE std::pair<typename UnorderedStringMultimap<ValueType>::iterator,
typename UnorderedStringMultimap<ValueType>::iterator>
UnorderedStringMultiMapEqualRange(UnorderedStringMultimap<ValueType>& map, const KeyType& key)
{
return map.equal_range(key);
}
#else
template<typename ValueType>
using UnorderedStringMap = std::unordered_map<std::string, ValueType>;
template<typename ValueType>
using UnorderedStringMultimap = std::unordered_multimap<std::string, ValueType>;
using UnorderedStringSet = std::unordered_set<std::string>;
using UnorderedStringMultiSet = std::unordered_multiset<std::string>;
template<typename KeyType, typename ValueType>
ALWAYS_INLINE typename UnorderedStringMap<ValueType>::const_iterator
UnorderedStringMapFind(const UnorderedStringMap<ValueType>& map, const KeyType& key)
{
return map.find(std::string(key));
}
template<typename KeyType, typename ValueType>
ALWAYS_INLINE typename UnorderedStringMap<ValueType>::iterator
UnorderedStringMapFind(UnorderedStringMap<ValueType>& map, const KeyType& key)
{
return map.find(std::string(key));
}
template<typename KeyType, typename ValueType>
ALWAYS_INLINE typename UnorderedStringMultimap<ValueType>::const_iterator
UnorderedStringMultiMapFind(const UnorderedStringMultimap<ValueType>& map, const KeyType& key)
{
return map.find(std::string(key));
}
template<typename KeyType, typename ValueType>
ALWAYS_INLINE std::pair<typename UnorderedStringMultimap<ValueType>::const_iterator,
typename UnorderedStringMultimap<ValueType>::const_iterator>
UnorderedStringMultiMapEqualRange(const UnorderedStringMultimap<ValueType>& map, const KeyType& key)
{
return map.equal_range(std::string(key));
}
template<typename KeyType, typename ValueType>
ALWAYS_INLINE typename UnorderedStringMultimap<ValueType>::iterator
UnorderedStringMultiMapFind(UnorderedStringMultimap<ValueType>& map, const KeyType& key)
{
return map.find(std::string(key));
}
template<typename KeyType, typename ValueType>
ALWAYS_INLINE std::pair<typename UnorderedStringMultimap<ValueType>::iterator,
typename UnorderedStringMultimap<ValueType>::iterator>
UnorderedStringMultiMapEqualRange(UnorderedStringMultimap<ValueType>& map, const KeyType& key)
{
return map.equal_range(std::string(key));
}
#endif
template<typename ValueType>
using StringMap = std::map<std::string, ValueType, detail::transparent_string_less>;
template<typename ValueType>

View file

@ -21,7 +21,7 @@ void MemorySettingsInterface::Clear()
bool MemorySettingsInterface::GetIntValue(const char* section, const char* key, s32* value) const
{
const auto sit = UnorderedStringMapFind(m_sections, section);
const auto sit = m_sections.find(section);
if (sit == m_sections.end())
return false;
@ -39,11 +39,11 @@ bool MemorySettingsInterface::GetIntValue(const char* section, const char* key,
bool MemorySettingsInterface::GetUIntValue(const char* section, const char* key, u32* value) const
{
const auto sit = UnorderedStringMapFind(m_sections, section);
const auto sit = m_sections.find(section);
if (sit == m_sections.end())
return false;
const auto iter = UnorderedStringMultiMapFind(sit->second, key);
const auto iter = sit->second.find(key);
if (iter == sit->second.end())
return false;
@ -57,11 +57,11 @@ bool MemorySettingsInterface::GetUIntValue(const char* section, const char* key,
bool MemorySettingsInterface::GetFloatValue(const char* section, const char* key, float* value) const
{
const auto sit = UnorderedStringMapFind(m_sections, section);
const auto sit = m_sections.find(section);
if (sit == m_sections.end())
return false;
const auto iter = UnorderedStringMultiMapFind(sit->second, key);
const auto iter = sit->second.find(key);
if (iter == sit->second.end())
return false;
@ -75,11 +75,11 @@ bool MemorySettingsInterface::GetFloatValue(const char* section, const char* key
bool MemorySettingsInterface::GetDoubleValue(const char* section, const char* key, double* value) const
{
const auto sit = UnorderedStringMapFind(m_sections, section);
const auto sit = m_sections.find(section);
if (sit == m_sections.end())
return false;
const auto iter = UnorderedStringMultiMapFind(sit->second, key);
const auto iter = sit->second.find(key);
if (iter == sit->second.end())
return false;
@ -93,11 +93,11 @@ bool MemorySettingsInterface::GetDoubleValue(const char* section, const char* ke
bool MemorySettingsInterface::GetBoolValue(const char* section, const char* key, bool* value) const
{
const auto sit = UnorderedStringMapFind(m_sections, section);
const auto sit = m_sections.find(section);
if (sit == m_sections.end())
return false;
const auto iter = UnorderedStringMultiMapFind(sit->second, key);
const auto iter = sit->second.find(key);
if (iter == sit->second.end())
return false;
@ -111,11 +111,11 @@ bool MemorySettingsInterface::GetBoolValue(const char* section, const char* key,
bool MemorySettingsInterface::GetStringValue(const char* section, const char* key, std::string* value) const
{
const auto sit = UnorderedStringMapFind(m_sections, section);
const auto sit = m_sections.find(section);
if (sit == m_sections.end())
return false;
const auto iter = UnorderedStringMultiMapFind(sit->second, key);
const auto iter = sit->second.find(key);
if (iter == sit->second.end())
return false;
@ -156,7 +156,7 @@ void MemorySettingsInterface::SetStringValue(const char* section, const char* ke
std::vector<std::pair<std::string, std::string>> MemorySettingsInterface::GetKeyValueList(const char* section) const
{
std::vector<std::pair<std::string, std::string>> output;
auto sit = UnorderedStringMapFind(m_sections, section);
auto sit = m_sections.find(section);
if (sit != m_sections.end())
{
for (const auto& it : sit->second)
@ -168,7 +168,7 @@ std::vector<std::pair<std::string, std::string>> MemorySettingsInterface::GetKey
void MemorySettingsInterface::SetKeyValueList(const char* section,
const std::vector<std::pair<std::string, std::string>>& items)
{
auto sit = UnorderedStringMapFind(m_sections, section);
auto sit = m_sections.find(section);
sit->second.clear();
for (const auto& [key, value] : items)
sit->second.emplace(key, value);
@ -176,11 +176,11 @@ void MemorySettingsInterface::SetKeyValueList(const char* section,
void MemorySettingsInterface::SetValue(const char* section, const char* key, std::string value)
{
auto sit = UnorderedStringMapFind(m_sections, section);
auto sit = m_sections.find(section);
if (sit == m_sections.end())
sit = m_sections.emplace(std::make_pair(std::string(section), KeyMap())).first;
const auto range = UnorderedStringMultiMapEqualRange(sit->second, key);
const auto range = sit->second.equal_range(key);
if (range.first == sit->second.end())
{
sit->second.emplace(std::string(key), std::move(value));
@ -203,10 +203,10 @@ std::vector<std::string> MemorySettingsInterface::GetStringList(const char* sect
{
std::vector<std::string> ret;
const auto sit = UnorderedStringMapFind(m_sections, section);
const auto sit = m_sections.find(section);
if (sit != m_sections.end())
{
const auto range = UnorderedStringMultiMapEqualRange(sit->second, key);
const auto range = sit->second.equal_range(key);
for (auto iter = range.first; iter != range.second; ++iter)
ret.emplace_back(iter->second);
}
@ -216,11 +216,11 @@ std::vector<std::string> MemorySettingsInterface::GetStringList(const char* sect
void MemorySettingsInterface::SetStringList(const char* section, const char* key, const std::vector<std::string>& items)
{
auto sit = UnorderedStringMapFind(m_sections, section);
auto sit = m_sections.find(section);
if (sit == m_sections.end())
sit = m_sections.emplace(std::make_pair(std::string(section), KeyMap())).first;
const auto range = UnorderedStringMultiMapEqualRange(sit->second, key);
const auto range = sit->second.equal_range(key);
for (auto iter = range.first; iter != range.second;)
sit->second.erase(iter++);
@ -231,11 +231,11 @@ void MemorySettingsInterface::SetStringList(const char* section, const char* key
bool MemorySettingsInterface::RemoveFromStringList(const char* section, const char* key, const char* item)
{
auto sit = UnorderedStringMapFind(m_sections, section);
auto sit = m_sections.find(section);
if (sit == m_sections.end())
sit = m_sections.emplace(std::make_pair(std::string(section), KeyMap())).first;
const auto range = UnorderedStringMultiMapEqualRange(sit->second, key);
const auto range = sit->second.equal_range(key);
bool result = false;
for (auto iter = range.first; iter != range.second;)
{
@ -255,11 +255,11 @@ bool MemorySettingsInterface::RemoveFromStringList(const char* section, const ch
bool MemorySettingsInterface::AddToStringList(const char* section, const char* key, const char* item)
{
auto sit = UnorderedStringMapFind(m_sections, section);
auto sit = m_sections.find(section);
if (sit == m_sections.end())
sit = m_sections.emplace(std::make_pair(std::string(section), KeyMap())).first;
const auto range = UnorderedStringMultiMapEqualRange(sit->second, key);
const auto range = sit->second.equal_range(key);
for (auto iter = range.first; iter != range.second; ++iter)
{
if (iter->second == item)
@ -272,7 +272,7 @@ bool MemorySettingsInterface::AddToStringList(const char* section, const char* k
bool MemorySettingsInterface::ContainsValue(const char* section, const char* key) const
{
const auto sit = UnorderedStringMapFind(m_sections, section);
const auto sit = m_sections.find(section);
if (sit == m_sections.end())
return false;
@ -281,18 +281,18 @@ bool MemorySettingsInterface::ContainsValue(const char* section, const char* key
void MemorySettingsInterface::DeleteValue(const char* section, const char* key)
{
auto sit = UnorderedStringMapFind(m_sections, section);
auto sit = m_sections.find(section);
if (sit == m_sections.end())
return;
const auto range = UnorderedStringMultiMapEqualRange(sit->second, key);
const auto range = sit->second.equal_range(key);
for (auto iter = range.first; iter != range.second;)
sit->second.erase(iter++);
}
void MemorySettingsInterface::ClearSection(const char* section)
{
auto sit = UnorderedStringMapFind(m_sections, section);
auto sit = m_sections.find(section);
if (sit == m_sections.end())
return;

View file

@ -115,7 +115,7 @@ const GameDatabase::Entry* GameDatabase::GetEntryForId(const std::string_view& c
EnsureLoaded();
auto iter = UnorderedStringMapFind(s_code_lookup, code);
auto iter = s_code_lookup.find(code);
return (iter != s_code_lookup.end()) ? &s_entries[iter->second] : nullptr;
}
@ -1005,7 +1005,7 @@ bool GameDatabase::ParseJsonCodes(u32 index, const rapidjson::Value& value)
}
const std::string_view code(current_code.GetString(), current_code.GetStringLength());
auto iter = UnorderedStringMapFind(s_code_lookup, code);
auto iter = s_code_lookup.find(code);
if (iter != s_code_lookup.end())
{
Log_WarningPrintf("Duplicate code '%.*s'", static_cast<int>(code.size()), code.data());

View file

@ -285,7 +285,7 @@ bool GameList::PopulateEntryFromPath(const std::string& path, Entry* entry)
bool GameList::GetGameListEntryFromCache(const std::string& path, Entry* entry)
{
auto iter = UnorderedStringMapFind(s_cache_map, path);
auto iter = s_cache_map.find(path);
if (iter == s_cache_map.end())
return false;
@ -333,7 +333,7 @@ bool GameList::LoadEntriesFromCache(ByteStream* stream)
ge.type = static_cast<EntryType>(type);
ge.compatibility = static_cast<GameDatabase::CompatibilityRating>(compatibility_rating);
auto iter = UnorderedStringMapFind(s_cache_map, ge.path);
auto iter = s_cache_map.find(ge.path);
if (iter != s_cache_map.end())
iter->second = std::move(ge);
else
@ -512,7 +512,7 @@ bool GameList::AddFileFromCache(const std::string& path, std::time_t timestamp,
if (!GetGameListEntryFromCache(path, &entry) || entry.last_modified_time != timestamp)
return false;
auto iter = UnorderedStringMapFind(played_time_map, entry.serial);
auto iter = played_time_map.find(entry.serial);
if (iter != played_time_map.end())
{
entry.last_played_time = iter->second.last_played_time;
@ -544,7 +544,7 @@ bool GameList::ScanFile(std::string path, std::time_t timestamp, std::unique_loc
Log_WarningPrintf("Failed to write entry '%s' to cache", entry.path.c_str());
}
auto iter = UnorderedStringMapFind(played_time_map, entry.serial);
auto iter = played_time_map.find(entry.serial);
if (iter != played_time_map.end())
{
entry.last_played_time = iter->second.last_played_time;
@ -821,7 +821,7 @@ GameList::PlayedTimeMap GameList::LoadPlayedTimeMap(const std::string& path)
if (!ParsePlayedTimeLine(line, serial, entry))
continue;
if (UnorderedStringMapFind(ret, serial) != ret.end())
if (ret.find(serial) != ret.end())
{
Log_WarningPrintf("Duplicate entry: '%s'", serial.c_str());
continue;

View file

@ -44,12 +44,12 @@ std::pair<const char*, u32> Host::LookupTranslationString(const std::string_view
}
s_translation_string_mutex.lock_shared();
ctx_it = UnorderedStringMapFind(s_translation_string_map, context);
ctx_it = s_translation_string_map.find(context);
if (UNLIKELY(ctx_it == s_translation_string_map.end()))
goto add_string;
msg_it = UnorderedStringMapFind(ctx_it->second, msg);
msg_it = ctx_it->second.find(msg);
if (UNLIKELY(msg_it == ctx_it->second.end()))
goto add_string;