Skip to content

Commit

Permalink
Merge pull request #12945 from Tilka/erase_if
Browse files Browse the repository at this point in the history
Use C++20 erase_if() instead of erase(remove_if()) (NFC)
  • Loading branch information
Tilka authored Jul 21, 2024
2 parents 6522450 + 982893b commit 7bd2a7b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
7 changes: 3 additions & 4 deletions Source/Core/Core/CoreTiming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,12 @@ void CoreTimingManager::ScheduleEvent(s64 cycles_into_future, EventType* event_t

void CoreTimingManager::RemoveEvent(EventType* event_type)
{
auto itr = std::remove_if(m_event_queue.begin(), m_event_queue.end(),
[&](const Event& e) { return e.type == event_type; });
const size_t erased =
std::erase_if(m_event_queue, [&](const Event& e) { return e.type == event_type; });

// Removing random items breaks the invariant so we have to re-establish it.
if (itr != m_event_queue.end())
if (erased != 0)
{
m_event_queue.erase(itr, m_event_queue.end());
std::make_heap(m_event_queue.begin(), m_event_queue.end(), std::greater<Event>());
}
}
Expand Down
8 changes: 3 additions & 5 deletions Source/Core/DiscIO/DiscUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,9 @@ u64 GetBiggestReferencedOffset(const Volume& volume)
// This can happen when certain programs that create WBFS files scrub the entirety of
// the Masterpiece partitions in Super Smash Bros. Brawl without removing them from
// the partition table. https://bugs.dolphin-emu.org/issues/8733
const auto it =
std::remove_if(partitions.begin(), partitions.end(), [&](const Partition& partition) {
return volume.ReadSwapped<u32>(0x18, partition) != WII_DISC_MAGIC;
});
partitions.erase(it, partitions.end());
std::erase_if(partitions, [&](const Partition& partition) {
return volume.ReadSwapped<u32>(0x18, partition) != WII_DISC_MAGIC;
});

if (partitions.empty())
partitions.push_back(PARTITION_NONE);
Expand Down
14 changes: 5 additions & 9 deletions Source/Core/DolphinQt/GameList/GameList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,15 +803,11 @@ bool GameList::AddShortcutToDesktop()

std::string game_name = game->GetName(Core::TitleDatabase());
// Sanitize the string by removing all characters that cannot be used in NTFS file names
game_name.erase(std::remove_if(game_name.begin(), game_name.end(),
[](char ch) {
static constexpr char illegal_characters[] = {
'<', '>', ':', '\"', '/', '\\', '|', '?', '*'};
return std::find(std::begin(illegal_characters),
std::end(illegal_characters),
ch) != std::end(illegal_characters);
}),
game_name.end());
std::erase_if(game_name, [](char ch) {
static constexpr char illegal_characters[] = {'<', '>', ':', '\"', '/', '\\', '|', '?', '*'};
return std::find(std::begin(illegal_characters), std::end(illegal_characters), ch) !=
std::end(illegal_characters);
});

std::wstring desktop_path = std::wstring(desktop.get()) + UTF8ToTStr("\\" + game_name + ".lnk");
auto persist_file = shell_link.try_query<IPersistFile>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,17 +308,15 @@ void ControllerInterface::RemoveDevice(std::function<bool(const ciface::Core::De
bool any_removed;
{
std::lock_guard lk(m_devices_mutex);
auto it = std::remove_if(m_devices.begin(), m_devices.end(), [&callback](const auto& dev) {
const size_t erased = std::erase_if(m_devices, [&callback](const auto& dev) {
if (callback(dev.get()))
{
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "Removed device: {}", dev->GetQualifiedName());
return true;
}
return false;
});
const size_t prev_size = m_devices.size();
m_devices.erase(it, m_devices.end());
any_removed = m_devices.size() != prev_size;
any_removed = erased != 0;
}

if (any_removed && (!m_populating_devices_counter || force_devices_release))
Expand Down

0 comments on commit 7bd2a7b

Please sign in to comment.