From 314f411b13588207d6f8bceadc2d3121b5a8b6e6 Mon Sep 17 00:00:00 2001 From: AJR Date: Sat, 16 Feb 2019 21:27:06 -0500 Subject: Eliminate qsort usage in debugger (nw) --- src/emu/debug/dvbpoints.cpp | 51 ++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 31 deletions(-) (limited to 'src/emu/debug/dvbpoints.cpp') diff --git a/src/emu/debug/dvbpoints.cpp b/src/emu/debug/dvbpoints.cpp index 6bc4a008c5f..3b76c7d26fe 100644 --- a/src/emu/debug/dvbpoints.cpp +++ b/src/emu/debug/dvbpoints.cpp @@ -12,79 +12,68 @@ #include "debugger.h" #include "dvbpoints.h" +#include #include // Sorting functors for the qsort function -static int cIndexAscending(const void* a, const void* b) +static bool cIndexAscending(const device_debug::breakpoint *a, const device_debug::breakpoint *b) { - const device_debug::breakpoint* left = *(device_debug::breakpoint**)a; - const device_debug::breakpoint* right = *(device_debug::breakpoint**)b; - return left->index() - right->index(); + return a->index() < b->index(); } -static int cIndexDescending(const void* a, const void* b) +static bool cIndexDescending(const device_debug::breakpoint *a, const device_debug::breakpoint *b) { return cIndexAscending(b, a); } -static int cEnabledAscending(const void* a, const void* b) +static bool cEnabledAscending(const device_debug::breakpoint *a, const device_debug::breakpoint *b) { - const device_debug::breakpoint* left = *(device_debug::breakpoint**)a; - const device_debug::breakpoint* right = *(device_debug::breakpoint**)b; - return (left->enabled() ? 1 : 0) - (right->enabled() ? 1 : 0); + return !a->enabled() && b->enabled(); } -static int cEnabledDescending(const void* a, const void* b) +static bool cEnabledDescending(const device_debug::breakpoint *a, const device_debug::breakpoint *b) { return cEnabledAscending(b, a); } -static int cCpuAscending(const void* a, const void* b) +static bool cCpuAscending(const device_debug::breakpoint *a, const device_debug::breakpoint *b) { - const device_debug::breakpoint* left = *(device_debug::breakpoint**)a; - const device_debug::breakpoint* right = *(device_debug::breakpoint**)b; - return strcmp(left->debugInterface()->device().tag(), right->debugInterface()->device().tag()); + return strcmp(a->debugInterface()->device().tag(), b->debugInterface()->device().tag()) < 0; } -static int cCpuDescending(const void* a, const void* b) +static bool cCpuDescending(const device_debug::breakpoint *a, const device_debug::breakpoint *b) { return cCpuAscending(b, a); } -static int cAddressAscending(const void* a, const void* b) +static bool cAddressAscending(const device_debug::breakpoint *a, const device_debug::breakpoint *b) { - const device_debug::breakpoint* left = *(device_debug::breakpoint**)a; - const device_debug::breakpoint* right = *(device_debug::breakpoint**)b; - return (left->address() > right->address()) ? 1 : (left->address() < right->address()) ? -1 : 0; + return a->address() < b->address(); } -static int cAddressDescending(const void* a, const void* b) +static bool cAddressDescending(const device_debug::breakpoint *a, const device_debug::breakpoint *b) { return cAddressAscending(b, a); } -static int cConditionAscending(const void* a, const void* b) +static bool cConditionAscending(const device_debug::breakpoint *a, const device_debug::breakpoint *b) { - const device_debug::breakpoint* left = *(device_debug::breakpoint**)a; - const device_debug::breakpoint* right = *(device_debug::breakpoint**)b; - return strcmp(left->condition(), right->condition()); + return strcmp(a->condition(), b->condition()) < 0; } -static int cConditionDescending(const void* a, const void* b) +static bool cConditionDescending(const device_debug::breakpoint *a, const device_debug::breakpoint *b) { return cConditionAscending(b, a); } -static int cActionAscending(const void* a, const void* b) +static bool cActionAscending(const device_debug::breakpoint *a, const device_debug::breakpoint *b) { - const device_debug::breakpoint* left = *(device_debug::breakpoint**)a; - const device_debug::breakpoint* right = *(device_debug::breakpoint**)b; - return strcmp(left->action(), right->action()); + return strcmp(a->action(), b->action()) < 0; } -static int cActionDescending(const void* a, const void* b) +static bool cActionDescending(const device_debug::breakpoint *a, const device_debug::breakpoint *b) { return cActionAscending(b, a); } @@ -210,7 +199,7 @@ void debug_view_breakpoints::gather_breakpoints() // And now for the sort if (!m_buffer.empty()) - qsort(&m_buffer[0], m_buffer.size(), sizeof(device_debug::breakpoint *), m_sortType); + std::stable_sort(m_buffer.begin(), m_buffer.end(), m_sortType); } -- cgit v1.2.3-70-g09d2