Merge pull request #13794 from Sintendo/doouble-lookup
Avoid map/set double lookups
This commit is contained in:
15 files changed
+69
-74
No files matched your search
@@ -192,8 +192,8 @@ void AchievementManager::LoadGame(const DiscIO::Volume* volume)
|
||||
std::lock_guard lg{m_lock};
|
||||
#ifdef RC_CLIENT_SUPPORTS_RAINTEGRATION
|
||||
const auto& names = volume->GetLongNames();
|
||||
if (names.contains(DiscIO::Language::English))
|
||||
m_title_estimate = names.at(DiscIO::Language::English);
|
||||
if (const auto it = names.find(DiscIO::Language::English); it != names.end())
|
||||
m_title_estimate = it->second;
|
||||
else if (!names.empty())
|
||||
m_title_estimate = names.begin()->second;
|
||||
else
|
||||
|
||||
@@ -964,8 +964,9 @@ s32 WiiSockMan::NewSocket(s32 af, s32 type, s32 protocol)
|
||||
|
||||
s32 WiiSockMan::GetHostSocket(s32 wii_fd) const
|
||||
{
|
||||
if (WiiSockets.contains(wii_fd))
|
||||
return WiiSockets.at(wii_fd).fd;
|
||||
auto socket_entry = WiiSockets.find(wii_fd);
|
||||
if (socket_entry != WiiSockets.end())
|
||||
return socket_entry->second.fd;
|
||||
return -EBADF;
|
||||
}
|
||||
|
||||
|
||||
@@ -186,9 +186,10 @@ FigureData SkylanderFigure::GetData() const
|
||||
|
||||
auto filter = std::make_pair(figure_data.figure_id, figure_data.variant_id);
|
||||
Type type = Type::Item;
|
||||
if (IOS::HLE::USB::list_skylanders.contains(filter))
|
||||
if (const auto it = IOS::HLE::USB::list_skylanders.find(filter);
|
||||
it != IOS::HLE::USB::list_skylanders.end())
|
||||
{
|
||||
auto found = IOS::HLE::USB::list_skylanders.at(filter);
|
||||
auto found = it->second;
|
||||
type = found.type;
|
||||
}
|
||||
|
||||
|
||||
@@ -176,9 +176,9 @@ std::optional<IPCReply> OH0::RegisterRemovalHook(const u64 device_id, const IOCt
|
||||
{
|
||||
std::lock_guard lock{m_hooks_mutex};
|
||||
// IOS only allows a single device removal hook.
|
||||
if (m_removal_hooks.contains(device_id))
|
||||
const bool inserted = m_removal_hooks.try_emplace(device_id, request.address).second;
|
||||
if (!inserted)
|
||||
return IPCReply(IPC_EEXIST);
|
||||
m_removal_hooks.insert({device_id, request.address});
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
@@ -171,16 +171,20 @@ void USB_HIDv4::OnDeviceChange(ChangeEvent event, std::shared_ptr<USB::Device> d
|
||||
std::lock_guard id_map_lock{m_id_map_mutex};
|
||||
if (event == ChangeEvent::Inserted)
|
||||
{
|
||||
const auto id = device->GetId();
|
||||
s32 new_id = 0;
|
||||
while (m_ios_ids.contains(new_id))
|
||||
while (!m_ios_ids.emplace(new_id, id).second)
|
||||
++new_id;
|
||||
m_ios_ids[new_id] = device->GetId();
|
||||
m_device_ids[device->GetId()] = new_id;
|
||||
|
||||
m_device_ids[id] = new_id;
|
||||
}
|
||||
else if (event == ChangeEvent::Removed && m_device_ids.contains(device->GetId()))
|
||||
else if (event == ChangeEvent::Removed)
|
||||
{
|
||||
m_ios_ids.erase(m_device_ids.at(device->GetId()));
|
||||
m_device_ids.erase(device->GetId());
|
||||
if (const auto it = m_device_ids.find(device->GetId()); it != m_device_ids.end())
|
||||
{
|
||||
m_ios_ids.erase(it->second);
|
||||
m_device_ids.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2392,8 +2392,8 @@ void NetPlayClient::RequestGolfControl()
|
||||
std::string NetPlayClient::GetCurrentGolfer()
|
||||
{
|
||||
std::lock_guard lkp(m_crit.players);
|
||||
if (m_players.contains(m_current_golfer))
|
||||
return m_players[m_current_golfer].name;
|
||||
if (const auto it = m_players.find(m_current_golfer); it != m_players.end())
|
||||
return it->second.name;
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@@ -290,8 +290,8 @@ void NetPlayServer::ThreadFunc()
|
||||
auto& e = m_async_queue.Front();
|
||||
if (e.target_mode == TargetMode::Only)
|
||||
{
|
||||
if (m_players.contains(e.target_pid))
|
||||
Send(m_players.at(e.target_pid).socket, e.packet, e.channel_id);
|
||||
if (const auto it = m_players.find(e.target_pid); it != m_players.end())
|
||||
Send(it->second.socket, e.packet, e.channel_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -794,9 +794,10 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
|
||||
u32 cid;
|
||||
packet >> cid;
|
||||
|
||||
if (m_chunked_data_complete_count.contains(cid))
|
||||
if (const auto it = m_chunked_data_complete_count.find(cid);
|
||||
it != m_chunked_data_complete_count.end())
|
||||
{
|
||||
m_chunked_data_complete_count[cid]++;
|
||||
it->second++;
|
||||
m_chunked_data_complete_event.Set();
|
||||
}
|
||||
}
|
||||
@@ -839,8 +840,11 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
|
||||
if (m_host_input_authority)
|
||||
{
|
||||
// Prevent crash before game stop if the golfer disconnects
|
||||
if (m_current_golfer != 0 && m_players.contains(m_current_golfer))
|
||||
Send(m_players.at(m_current_golfer).socket, spac);
|
||||
if (m_current_golfer != 0)
|
||||
{
|
||||
if (const auto it = m_players.find(m_current_golfer); it != m_players.end())
|
||||
Send(it->second.socket, spac);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -40,9 +40,10 @@ const void* ConstantPool::GetConstant(const void* value, size_t element_size, si
|
||||
size_t index)
|
||||
{
|
||||
const size_t value_size = element_size * num_elements;
|
||||
auto iter = m_const_info.find(value);
|
||||
const auto [iter, inserted] = m_const_info.emplace(value, ConstantInfo{});
|
||||
ConstantInfo& info = iter->second;
|
||||
|
||||
if (iter == m_const_info.end())
|
||||
if (inserted)
|
||||
{
|
||||
void* ptr = std::align(ALIGNMENT, value_size, m_current_ptr, m_remaining_size);
|
||||
ASSERT_MSG(DYNA_REC, ptr, "Constant pool has run out of space.");
|
||||
@@ -51,10 +52,9 @@ const void* ConstantPool::GetConstant(const void* value, size_t element_size, si
|
||||
m_remaining_size -= value_size;
|
||||
|
||||
std::memcpy(ptr, value, value_size);
|
||||
iter = m_const_info.emplace(std::make_pair(value, ConstantInfo{ptr, value_size})).first;
|
||||
info = ConstantInfo{ptr, value_size};
|
||||
}
|
||||
|
||||
const ConstantInfo& info = iter->second;
|
||||
ASSERT_MSG(DYNA_REC, info.m_size == value_size, "Constant has incorrect size in constant pool.");
|
||||
u8* location = static_cast<u8*>(info.m_location);
|
||||
return location + element_size * index;
|
||||
|
||||
@@ -727,12 +727,12 @@ static bool ValidateHeaders(const StateHeader& header)
|
||||
std::string loaded_str = header.version_string;
|
||||
const u32 loaded_version = header.version_header.version_cookie - COOKIE_BASE;
|
||||
|
||||
if (s_old_versions.contains(loaded_version))
|
||||
if (const auto it = s_old_versions.find(loaded_version); it != s_old_versions.end())
|
||||
{
|
||||
// This is a REALLY old version, before we started writing the version string to file
|
||||
success = false;
|
||||
|
||||
std::pair<std::string, std::string> version_range = s_old_versions.find(loaded_version)->second;
|
||||
std::pair<std::string, std::string> version_range = it->second;
|
||||
std::string oldest_version = version_range.first;
|
||||
std::string newest_version = version_range.second;
|
||||
|
||||
|
||||
Reference in new issue
Block a user