Merge pull request #12990 from tygyh/Use-contains-method

Use 'contains' method
This commit is contained in:
Tilka 2024-08-14 23:54:16 +01:00 committed by GitHub
commit 18ac8bf405
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
31 changed files with 46 additions and 52 deletions

View File

@ -75,7 +75,7 @@ bool IniFile::Section::Get(std::string_view key, std::string* value,
bool IniFile::Section::Exists(std::string_view key) const
{
return values.find(key) != values.end();
return values.contains(key);
}
bool IniFile::Section::Delete(std::string_view key)

View File

@ -235,7 +235,7 @@ std::unique_ptr<BootParameters> BootParameters::GenerateFromFile(std::vector<std
static const std::unordered_set<std::string> disc_image_extensions = {
{".gcm", ".iso", ".tgc", ".wbfs", ".ciso", ".gcz", ".wia", ".rvz", ".nfs", ".dol", ".elf"}};
if (disc_image_extensions.find(extension) != disc_image_extensions.end())
if (disc_image_extensions.contains(extension))
{
std::unique_ptr<DiscIO::VolumeDisc> disc = DiscIO::CreateDisc(path);
if (disc)

View File

@ -43,7 +43,7 @@ static bool IsSoundFile(const std::string& filename)
".str", // Harry Potter & the Sorcerer's Stone
};
return extensions.find(extension) != extensions.end();
return extensions.contains(extension);
}
FileLogger::FileLogger() = default;

View File

@ -1000,7 +1000,7 @@ bool IsBalanceBoardName(const std::string& name)
bool IsNewWiimote(const std::string& identifier)
{
std::lock_guard lk(s_known_ids_mutex);
return s_known_ids.count(identifier) == 0;
return !s_known_ids.contains(identifier);
}
void HandleWiimoteSourceChange(unsigned int index)

View File

@ -1049,7 +1049,7 @@ ReturnCode ESCore::WriteNewCertToStore(const ES::CertReader& cert)
{
const std::map<std::string, ES::CertReader> certs = ES::ParseCertChain(current_store);
// The cert is already present in the store. Nothing to do.
if (certs.find(cert.GetName()) != certs.end())
if (certs.contains(cert.GetName()))
return IPC_SUCCESS;
}

View File

@ -340,7 +340,7 @@ bool ESCore::FinishImport(const ES::TMDReader& tmd)
// There should not be any directory in there. Remove it.
if (fs->ReadDirectory(PID_KERNEL, PID_KERNEL, absolute_path))
fs->Delete(PID_KERNEL, PID_KERNEL, absolute_path);
else if (expected_entries.find(name) == expected_entries.end())
else if (!expected_entries.contains(name))
fs->Delete(PID_KERNEL, PID_KERNEL, absolute_path);
}

View File

@ -876,7 +876,7 @@ s32 WiiSockMan::AddSocket(s32 fd, bool is_rw)
for (wii_fd = 0; wii_fd < WII_SOCKET_FD_MAX; ++wii_fd)
{
// Find an available socket fd
if (WiiSockets.count(wii_fd) == 0)
if (!WiiSockets.contains(wii_fd))
break;
}
@ -964,7 +964,7 @@ s32 WiiSockMan::NewSocket(s32 af, s32 type, s32 protocol)
s32 WiiSockMan::GetHostSocket(s32 wii_fd) const
{
if (WiiSockets.count(wii_fd) > 0)
if (WiiSockets.contains(wii_fd))
return WiiSockets.at(wii_fd).fd;
return -EBADF;
}

View File

@ -678,7 +678,7 @@ bool BluetoothRealDevice::OpenDevice(libusb_device* device)
void BluetoothRealDevice::HandleCtrlTransfer(libusb_transfer* tr)
{
std::lock_guard lk(m_transfers_mutex);
if (!m_current_transfers.count(tr))
if (!m_current_transfers.contains(tr))
return;
if (tr->status != LIBUSB_TRANSFER_COMPLETED && tr->status != LIBUSB_TRANSFER_NO_DEVICE)
@ -706,7 +706,7 @@ void BluetoothRealDevice::HandleCtrlTransfer(libusb_transfer* tr)
void BluetoothRealDevice::HandleBulkOrIntrTransfer(libusb_transfer* tr)
{
std::lock_guard lk(m_transfers_mutex);
if (!m_current_transfers.count(tr))
if (!m_current_transfers.contains(tr))
return;
if (tr->status != LIBUSB_TRANSFER_COMPLETED && tr->status != LIBUSB_TRANSFER_TIMED_OUT &&

View File

@ -188,7 +188,7 @@ u16 WiimoteDevice::GenerateChannelID() const
u16 cid = starting_id;
while (m_channels.count(cid) != 0)
while (m_channels.contains(cid))
++cid;
return cid;

View File

@ -149,7 +149,7 @@ private:
bool LinkChannel(u16 psm);
u16 GenerateChannelID() const;
bool DoesChannelExist(u16 scid) const { return m_channels.count(scid) != 0; }
bool DoesChannelExist(u16 scid) const { return m_channels.contains(scid); }
void SendCommandToACL(u8 ident, u8 code, u8 command_length, u8* command_data);
void SignalChannel(u8* data, u32 size);

View File

@ -186,7 +186,7 @@ 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.count(filter) != 0)
if (IOS::HLE::USB::list_skylanders.contains(filter))
{
auto found = IOS::HLE::USB::list_skylanders.at(filter);
type = found.type;

View File

@ -72,7 +72,7 @@ void USBHost::DoState(PointerWrap& p)
bool USBHost::AddDevice(std::unique_ptr<USB::Device> device)
{
std::lock_guard lk(m_devices_mutex);
if (m_devices.find(device->GetId()) != m_devices.end())
if (m_devices.contains(device->GetId()))
return false;
m_devices[device->GetId()] = std::move(device);
@ -136,7 +136,7 @@ bool USBHost::AddNewDevices(std::set<u64>& new_devices, DeviceChangeHooks& hooks
const int ret = m_context.GetDeviceList([&](libusb_device* device) {
libusb_device_descriptor descriptor;
libusb_get_device_descriptor(device, &descriptor);
if (whitelist.count({descriptor.idVendor, descriptor.idProduct}) == 0)
if (!whitelist.contains({descriptor.idVendor, descriptor.idProduct}))
return true;
auto usb_device =
@ -157,7 +157,7 @@ void USBHost::DetectRemovedDevices(const std::set<u64>& plugged_devices, DeviceC
std::lock_guard lk(m_devices_mutex);
for (auto it = m_devices.begin(); it != m_devices.end();)
{
if (plugged_devices.find(it->second->GetId()) == plugged_devices.end())
if (!plugged_devices.contains(it->second->GetId()))
{
hooks.emplace(it->second, ChangeEvent::Removed);
it = m_devices.erase(it);

View File

@ -176,7 +176,7 @@ 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.find(device_id) != m_removal_hooks.end())
if (m_removal_hooks.contains(device_id))
return IPCReply(IPC_EEXIST);
m_removal_hooks.insert({device_id, request.address});
return std::nullopt;
@ -271,8 +271,7 @@ std::pair<ReturnCode, u64> OH0::DeviceOpen(const u16 vid, const u16 pid)
continue;
has_device_with_vid_pid = true;
if (m_opened_devices.find(device.second->GetId()) != m_opened_devices.cend() ||
!device.second->Attach())
if (m_opened_devices.contains(device.second->GetId()) || !device.second->Attach())
{
continue;
}

View File

@ -173,13 +173,12 @@ void USB_HIDv4::OnDeviceChange(ChangeEvent event, std::shared_ptr<USB::Device> d
if (event == ChangeEvent::Inserted)
{
s32 new_id = 0;
while (m_ios_ids.find(new_id) != m_ios_ids.cend())
while (m_ios_ids.contains(new_id))
++new_id;
m_ios_ids[new_id] = device->GetId();
m_device_ids[device->GetId()] = new_id;
}
else if (event == ChangeEvent::Removed &&
m_device_ids.find(device->GetId()) != m_device_ids.cend())
else if (event == ChangeEvent::Removed && m_device_ids.contains(device->GetId()))
{
m_ios_ids.erase(m_device_ids.at(device->GetId()));
m_device_ids.erase(device->GetId());

View File

@ -2388,7 +2388,7 @@ void NetPlayClient::RequestGolfControl()
std::string NetPlayClient::GetCurrentGolfer()
{
std::lock_guard lkp(m_crit.players);
if (m_players.count(m_current_golfer))
if (m_players.contains(m_current_golfer))
return m_players[m_current_golfer].name;
return "";
}

View File

@ -283,7 +283,7 @@ void NetPlayServer::ThreadFunc()
auto& e = m_async_queue.Front();
if (e.target_mode == TargetMode::Only)
{
if (m_players.find(e.target_pid) != m_players.end())
if (m_players.contains(e.target_pid))
Send(m_players.at(e.target_pid).socket, e.packet, e.channel_id);
}
else
@ -787,7 +787,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
u32 cid;
packet >> cid;
if (m_chunked_data_complete_count.find(cid) != m_chunked_data_complete_count.end())
if (m_chunked_data_complete_count.contains(cid))
{
m_chunked_data_complete_count[cid]++;
m_chunked_data_complete_event.Set();
@ -832,7 +832,7 @@ 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.find(m_current_golfer) != m_players.end())
if (m_current_golfer != 0 && m_players.contains(m_current_golfer))
Send(m_players.at(m_current_golfer).socket, spac);
}
else
@ -917,7 +917,7 @@ unsigned int NetPlayServer::OnData(sf::Packet& packet, Client& player)
packet >> pid;
// Check if player ID is valid and sender isn't a spectator
if (!m_players.count(pid) || !PlayerHasControllerMapped(player.pid))
if (!m_players.contains(pid) || !PlayerHasControllerMapped(player.pid))
break;
if (m_host_input_authority && m_settings.golf_mode && m_pending_golfer == 0 &&
@ -2426,7 +2426,7 @@ void NetPlayServer::ChunkedDataThreadFunc()
}
if (e.target_mode == TargetMode::Only)
{
if (m_players.find(e.target_pid) == m_players.end())
if (!m_players.contains(e.target_pid))
{
skip_wait = true;
break;

View File

@ -909,7 +909,7 @@ bool Jit64::DoJit(u32 em_address, JitBlock* b, u32 nextPC)
// Assume that GQR values don't change often at runtime. Many paired-heavy games use largely float
// loads and stores, which are significantly faster when inlined (especially in MMU mode, where
// this lets them use fastmem).
if (js.pairedQuantizeAddresses.find(js.blockStart) == js.pairedQuantizeAddresses.end())
if (!js.pairedQuantizeAddresses.contains(js.blockStart))
{
// If there are GQRs used but not set, we'll treat those as constant and optimize them
BitSet8 gqr_static = ComputeStaticGQRs(code_block);
@ -938,8 +938,7 @@ bool Jit64::DoJit(u32 em_address, JitBlock* b, u32 nextPC)
}
}
if (js.noSpeculativeConstantsAddresses.find(js.blockStart) ==
js.noSpeculativeConstantsAddresses.end())
if (!js.noSpeculativeConstantsAddresses.contains(js.blockStart))
{
IntializeSpeculativeConstants();
}
@ -967,8 +966,7 @@ bool Jit64::DoJit(u32 em_address, JitBlock* b, u32 nextPC)
{
// Gather pipe writes using a non-immediate address are discovered by profiling.
const u32 prev_address = m_code_buffer[i - 1].address;
bool gatherPipeIntCheck =
js.fifoWriteAddresses.find(prev_address) != js.fifoWriteAddresses.end();
bool gatherPipeIntCheck = js.fifoWriteAddresses.contains(prev_address);
// Gather pipe writes using an immediate address are explicitly tracked.
if (jo.optimizeGatherPipe &&

View File

@ -1158,8 +1158,7 @@ bool JitArm64::DoJit(u32 em_address, JitBlock* b, u32 nextPC)
{
// Gather pipe writes using a non-immediate address are discovered by profiling.
const u32 prev_address = m_code_buffer[i - 1].address;
bool gatherPipeIntCheck =
js.fifoWriteAddresses.find(prev_address) != js.fifoWriteAddresses.end();
bool gatherPipeIntCheck = js.fifoWriteAddresses.contains(prev_address);
if (jo.optimizeGatherPipe &&
(js.fifoBytesSinceCheck >= GPFifo::GATHER_PIPE_SIZE || js.mustCheckFifo))

View File

@ -316,8 +316,7 @@ void JitInterface::CompileExceptionCheck(ExceptionType type)
}
auto& ppc_state = m_system.GetPPCState();
if (ppc_state.pc != 0 &&
(exception_addresses->find(ppc_state.pc)) == (exception_addresses->end()))
if (ppc_state.pc != 0 && !exception_addresses->contains(ppc_state.pc))
{
if (type == ExceptionType::FIFOWrite)
{

View File

@ -34,7 +34,7 @@ PPCSymbolDB::~PPCSymbolDB() = default;
Common::Symbol* PPCSymbolDB::AddFunction(const Core::CPUThreadGuard& guard, u32 start_addr)
{
// It's already in the list
if (m_functions.find(start_addr) != m_functions.end())
if (m_functions.contains(start_addr))
return nullptr;
Common::Symbol symbol;

View File

@ -742,7 +742,7 @@ 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.count(loaded_version))
if (s_old_versions.contains(loaded_version))
{
// This is a REALLY old version, before we started writing the version string to file
success = false;

View File

@ -532,7 +532,7 @@ UpdateResult OnlineSystemUpdater::InstallTitleFromNUS(const std::string& prefix_
if (title.id == Titles::BOOT2)
return UpdateResult::Succeeded;
if (!ShouldInstallTitle(title) || updated_titles->find(title.id) != updated_titles->end())
if (!ShouldInstallTitle(title) || updated_titles->contains(title.id))
return UpdateResult::Succeeded;
NOTICE_LOG_FMT(CORE, "Updating title {:016x}", title.id);

View File

@ -728,7 +728,7 @@ void CodeViewWidget::AutoStep(CodeTrace::AutoStop option)
for (u32 i = 1; i <= 3; i++)
{
if (results.mem_tracked.count(address + i))
if (results.mem_tracked.contains(address + i))
iter++;
else
break;

View File

@ -125,7 +125,7 @@ void ChunkedProgressDialog::SetProgress(const int pid, const u64 progress)
{
QString player_name = GetPlayerNameFromPID(pid);
if (!m_status_labels.count(pid))
if (!m_status_labels.contains(pid))
return;
const float acquired = progress / 1024.0f / 1024.0f;

View File

@ -122,7 +122,7 @@ void GameDigestDialog::SetProgress(int pid, int progress)
{
QString player_name = GetPlayerNameFromPID(pid);
if (!m_status_labels.count(pid))
if (!m_status_labels.contains(pid))
return;
m_status_labels[pid]->setText(
@ -134,7 +134,7 @@ void GameDigestDialog::SetResult(int pid, const std::string& result)
{
QString player_name = GetPlayerNameFromPID(pid);
if (!m_status_labels.count(pid))
if (!m_status_labels.contains(pid))
return;
m_status_labels[pid]->setText(

View File

@ -659,7 +659,7 @@ void NetPlayDialog::UpdateGUI()
auto* name_item = new QTableWidgetItem(QString::fromStdString(p->name));
name_item->setToolTip(name_item->text());
const auto& status_info = player_status.count(p->game_status) ?
const auto& status_info = player_status.contains(p->game_status) ?
player_status.at(p->game_status) :
std::make_pair(QStringLiteral("?"), QStringLiteral("?"));
auto* status_item = new QTableWidgetItem(status_info.first);

View File

@ -113,7 +113,7 @@ void USBDeviceAddToWhitelistDialog::RefreshDeviceList()
auto whitelist = Config::GetUSBDeviceWhitelist();
for (const auto& device : current_devices)
{
if (whitelist.count({device.first.first, device.first.second}) != 0)
if (whitelist.contains({device.first.first, device.first.second}))
continue;
usb_inserted_devices_list->addItem(QString::fromStdString(device.second));
}

View File

@ -44,7 +44,7 @@ void InitJoystick(IDirectInput8* const idi8, HWND hwnd)
for (DIDEVICEINSTANCE& joystick : joysticks)
{
// Skip XInput Devices
if (xinput_guids.count(joystick.guidProduct.Data1))
if (xinput_guids.contains(joystick.guidProduct.Data1))
{
continue;
}
@ -52,7 +52,7 @@ void InitJoystick(IDirectInput8* const idi8, HWND hwnd)
// Skip devices we are already using.
{
std::lock_guard lk(s_guids_mutex);
if (s_guids_in_use.count(joystick.guidInstance))
if (s_guids_in_use.contains(joystick.guidInstance))
{
continue;
}

View File

@ -279,7 +279,7 @@ TodoList ComputeActionsToDo(Manifest this_manifest, Manifest next_manifest)
// Delete if present in this manifest but not in next manifest.
for (const auto& entry : this_manifest.entries)
{
if (next_manifest.entries.find(entry.first) == next_manifest.entries.end())
if (!next_manifest.entries.contains(entry.first))
{
TodoList::DeleteOp del;
del.filename = entry.first;

View File

@ -197,7 +197,7 @@ void GraphicsModManager::Load(const GraphicsModGroupConfig& config)
{
for (const GraphicsTargetGroupConfig& group : mod.m_groups)
{
if (m_groups.find(group.m_name) != m_groups.end())
if (m_groups.contains(group.m_name))
{
WARN_LOG_FMT(
VIDEO,

View File

@ -665,7 +665,7 @@ void TextureCacheBase::DoSaveState(PointerWrap& p)
auto refpair1 = std::make_pair(*id1, *id2);
auto refpair2 = std::make_pair(*id2, *id1);
if (reference_pairs.count(refpair1) == 0 && reference_pairs.count(refpair2) == 0)
if (!reference_pairs.contains(refpair1) && !reference_pairs.contains(refpair2))
reference_pairs.insert(refpair1);
}
}
@ -854,7 +854,7 @@ RcTcacheEntry TextureCacheBase::DoPartialTextureUpdates(RcTcacheEntry& entry_to_
{
auto& entry = iter.first->second;
if (entry != entry_to_update && entry->IsCopy() &&
entry->references.count(entry_to_update.get()) == 0 &&
!entry->references.contains(entry_to_update.get()) &&
entry->OverlapsMemoryRange(entry_to_update->addr, entry_to_update->size_in_bytes) &&
entry->memory_stride == numBlocksX * block_size)
{