mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-24 15:01:16 +01:00
Modernize std::stable_sort
with ranges and projections
This commit is contained in:
parent
d96569a74a
commit
1c668350a0
@ -313,11 +313,6 @@ static std::vector<SlotWithTimestamp> GetUsedSlotsWithTimestamp()
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool CompareTimestamp(const SlotWithTimestamp& lhs, const SlotWithTimestamp& rhs)
|
||||
{
|
||||
return lhs.timestamp < rhs.timestamp;
|
||||
}
|
||||
|
||||
static void CompressBufferToFile(const u8* raw_buffer, u64 size, File::IOFile& f)
|
||||
{
|
||||
u64 total_bytes_compressed = 0;
|
||||
@ -1000,7 +995,7 @@ void LoadLastSaved(Core::System& system, int i)
|
||||
return;
|
||||
}
|
||||
|
||||
std::stable_sort(used_slots.begin(), used_slots.end(), CompareTimestamp);
|
||||
std::ranges::stable_sort(used_slots, {}, &SlotWithTimestamp::timestamp);
|
||||
Load(system, (used_slots.end() - i)->slot);
|
||||
}
|
||||
|
||||
@ -1016,7 +1011,7 @@ void SaveFirstSaved(Core::System& system)
|
||||
}
|
||||
|
||||
// overwrite the oldest state
|
||||
std::stable_sort(used_slots.begin(), used_slots.end(), CompareTimestamp);
|
||||
std::ranges::stable_sort(used_slots, {}, &SlotWithTimestamp::timestamp);
|
||||
Save(system, used_slots.front().slot, true);
|
||||
}
|
||||
|
||||
|
@ -1340,8 +1340,7 @@ void VolumeVerifier::Finish()
|
||||
}
|
||||
|
||||
// Show the most serious problems at the top
|
||||
std::stable_sort(m_result.problems.begin(), m_result.problems.end(),
|
||||
[](const Problem& p1, const Problem& p2) { return p1.severity > p2.severity; });
|
||||
std::ranges::stable_sort(m_result.problems, std::ranges::greater{}, &Problem::severity);
|
||||
const Severity highest_severity =
|
||||
m_result.problems.empty() ? Severity::None : m_result.problems[0].severity;
|
||||
|
||||
|
@ -433,13 +433,9 @@ void CodeViewWidget::CalculateBranchIndentation()
|
||||
|
||||
// process in order of how much vertical space the drawn arrow would take up
|
||||
// so shorter arrows go further to the left
|
||||
const auto priority = [](const CodeViewBranch& b) {
|
||||
std::ranges::stable_sort(m_branches, {}, [](const CodeViewBranch& b) {
|
||||
return b.is_link ? 0 : (std::max(b.src_addr, b.dst_addr) - std::min(b.src_addr, b.dst_addr));
|
||||
};
|
||||
std::stable_sort(m_branches.begin(), m_branches.end(),
|
||||
[&priority](const CodeViewBranch& lhs, const CodeViewBranch& rhs) {
|
||||
return priority(lhs) < priority(rhs);
|
||||
});
|
||||
});
|
||||
|
||||
// build a 2D lookup table representing the columns and rows the arrow could be drawn in
|
||||
// and try to place all branch arrows in it as far left as possible
|
||||
|
@ -273,18 +273,14 @@ bool ControllerInterface::AddDevice(std::shared_ptr<ciface::Core::Device> device
|
||||
NOTICE_LOG_FMT(CONTROLLERINTERFACE, "Added device: {}", device->GetQualifiedName());
|
||||
m_devices.emplace_back(std::move(device));
|
||||
|
||||
// We can't (and don't want) to control the order in which devices are added, but we
|
||||
// need their order to be consistent, and we need the same one to always be the first, where
|
||||
// present (the keyboard and mouse device usually). This is because when defaulting a
|
||||
// controller profile, it will automatically select the first device in the list as its default.
|
||||
std::stable_sort(m_devices.begin(), m_devices.end(),
|
||||
[](const std::shared_ptr<ciface::Core::Device>& a,
|
||||
const std::shared_ptr<ciface::Core::Device>& b) {
|
||||
// It would be nice to sort devices by Source then Name then ID but it's
|
||||
// better to leave them sorted by the add order, which also avoids breaking
|
||||
// the order on other platforms that are less tested.
|
||||
return a->GetSortPriority() > b->GetSortPriority();
|
||||
});
|
||||
// We can't (and don't want) to control the order in which devices are added, but we need
|
||||
// their order to be consistent, and we need the same one to always be the first, where present
|
||||
// (the keyboard and mouse device usually). This is because when defaulting a controller
|
||||
// profile, it will automatically select the first device in the list as its default. It would
|
||||
// be nice to sort devices by Source then Name then ID, but it's better to leave them sorted by
|
||||
// the add order. This also avoids breaking the order on other platforms that are less tested.
|
||||
std::ranges::stable_sort(m_devices, std::ranges::greater{},
|
||||
&ciface::Core::Device::GetSortPriority);
|
||||
}
|
||||
|
||||
if (!m_populating_devices_counter)
|
||||
|
Loading…
x
Reference in New Issue
Block a user