mirror of
https://github.com/holub/mame
synced 2025-04-23 08:49:55 +03:00
Eliminate qsort usage in debugger (nw)
This commit is contained in:
parent
9f7c4385a8
commit
314f411b13
@ -21,6 +21,7 @@
|
||||
#include "natkeyboard.h"
|
||||
#include "render.h"
|
||||
#include <ctype.h>
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
@ -3215,13 +3216,6 @@ void debugger_commands::execute_memdump(int ref, const std::vector<std::string>
|
||||
execute_symlist - execute the symlist command
|
||||
-------------------------------------------------*/
|
||||
|
||||
static int CLIB_DECL symbol_sort_compare(const void *item1, const void *item2)
|
||||
{
|
||||
const char *str1 = *(const char **)item1;
|
||||
const char *str2 = *(const char **)item2;
|
||||
return strcmp(str1, str2);
|
||||
}
|
||||
|
||||
void debugger_commands::execute_symlist(int ref, const std::vector<std::string> ¶ms)
|
||||
{
|
||||
device_t *cpu = nullptr;
|
||||
@ -3257,7 +3251,9 @@ void debugger_commands::execute_symlist(int ref, const std::vector<std::string>
|
||||
|
||||
/* sort the symbols */
|
||||
if (count > 1)
|
||||
qsort((void *)namelist, count, sizeof(namelist[0]), symbol_sort_compare);
|
||||
std::sort(&namelist[0], &namelist[count], [](const char *item1, const char *item2) {
|
||||
return strcmp(item1, item2) < 0;
|
||||
});
|
||||
|
||||
/* iterate over symbols and print out relevant ones */
|
||||
for (symnum = 0; symnum < count; symnum++)
|
||||
|
@ -12,79 +12,68 @@
|
||||
#include "debugger.h"
|
||||
#include "dvbpoints.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -48,7 +48,7 @@ private:
|
||||
|
||||
|
||||
// internal state
|
||||
int (*m_sortType)(void const *, void const *);
|
||||
bool (*m_sortType)(const device_debug::breakpoint *, const device_debug::breakpoint *);
|
||||
std::vector<device_debug::breakpoint *> m_buffer;
|
||||
};
|
||||
|
||||
|
@ -11,102 +11,87 @@
|
||||
#include "emu.h"
|
||||
#include "dvwpoints.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
|
||||
static int cIndexAscending(const void* a, const void* b)
|
||||
static bool cIndexAscending(const device_debug::watchpoint *a, const device_debug::watchpoint *b)
|
||||
{
|
||||
const device_debug::watchpoint* left = *(device_debug::watchpoint**)a;
|
||||
const device_debug::watchpoint* right = *(device_debug::watchpoint**)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::watchpoint *a, const device_debug::watchpoint *b)
|
||||
{
|
||||
return cIndexAscending(b, a);
|
||||
}
|
||||
|
||||
static int cEnabledAscending(const void* a, const void* b)
|
||||
static bool cEnabledAscending(const device_debug::watchpoint *a, const device_debug::watchpoint *b)
|
||||
{
|
||||
const device_debug::watchpoint* left = *(device_debug::watchpoint**)a;
|
||||
const device_debug::watchpoint* right = *(device_debug::watchpoint**)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::watchpoint *a, const device_debug::watchpoint *b)
|
||||
{
|
||||
return cEnabledAscending(b, a);
|
||||
}
|
||||
|
||||
static int cCpuAscending(const void* a, const void* b)
|
||||
static bool cCpuAscending(const device_debug::watchpoint *a, const device_debug::watchpoint *b)
|
||||
{
|
||||
const device_debug::watchpoint* left = *(device_debug::watchpoint**)a;
|
||||
const device_debug::watchpoint* right = *(device_debug::watchpoint**)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::watchpoint *a, const device_debug::watchpoint *b)
|
||||
{
|
||||
return cCpuAscending(b, a);
|
||||
}
|
||||
|
||||
static int cSpaceAscending(const void* a, const void* b)
|
||||
static bool cSpaceAscending(const device_debug::watchpoint *a, const device_debug::watchpoint *b)
|
||||
{
|
||||
const device_debug::watchpoint* left = *(device_debug::watchpoint**)a;
|
||||
const device_debug::watchpoint* right = *(device_debug::watchpoint**)b;
|
||||
return strcmp(left->space().name(), right->space().name());
|
||||
return strcmp(a->space().name(), b->space().name()) < 0;
|
||||
}
|
||||
|
||||
static int cSpaceDescending(const void* a, const void* b)
|
||||
static bool cSpaceDescending(const device_debug::watchpoint *a, const device_debug::watchpoint *b)
|
||||
{
|
||||
return cSpaceAscending(b, a);
|
||||
}
|
||||
|
||||
static int cAddressAscending(const void* a, const void* b)
|
||||
static bool cAddressAscending(const device_debug::watchpoint *a, const device_debug::watchpoint *b)
|
||||
{
|
||||
const device_debug::watchpoint* left = *(device_debug::watchpoint**)a;
|
||||
const device_debug::watchpoint* right = *(device_debug::watchpoint**)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::watchpoint *a, const device_debug::watchpoint *b)
|
||||
{
|
||||
return cAddressAscending(b, a);
|
||||
}
|
||||
|
||||
static int cTypeAscending(const void* a, const void* b)
|
||||
static bool cTypeAscending(const device_debug::watchpoint *a, const device_debug::watchpoint *b)
|
||||
{
|
||||
const device_debug::watchpoint* left = *(device_debug::watchpoint**)a;
|
||||
const device_debug::watchpoint* right = *(device_debug::watchpoint**)b;
|
||||
return int(left->type()) - int(right->type());
|
||||
return int(a->type()) < int(b->type());
|
||||
}
|
||||
|
||||
static int cTypeDescending(const void* a, const void* b)
|
||||
static bool cTypeDescending(const device_debug::watchpoint *a, const device_debug::watchpoint *b)
|
||||
{
|
||||
return cTypeAscending(b, a);
|
||||
}
|
||||
|
||||
static int cConditionAscending(const void* a, const void* b)
|
||||
static bool cConditionAscending(const device_debug::watchpoint *a, const device_debug::watchpoint *b)
|
||||
{
|
||||
const device_debug::watchpoint* left = *(device_debug::watchpoint**)a;
|
||||
const device_debug::watchpoint* right = *(device_debug::watchpoint**)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::watchpoint *a, const device_debug::watchpoint *b)
|
||||
{
|
||||
return cConditionAscending(b, a);
|
||||
}
|
||||
|
||||
static int cActionAscending(const void* a, const void* b)
|
||||
static bool cActionAscending(const device_debug::watchpoint *a, const device_debug::watchpoint *b)
|
||||
{
|
||||
const device_debug::watchpoint* left = *(device_debug::watchpoint**)a;
|
||||
const device_debug::watchpoint* right = *(device_debug::watchpoint**)b;
|
||||
return left->action().compare(right->action());
|
||||
return a->action() < b->action();
|
||||
}
|
||||
|
||||
static int cActionDescending(const void* a, const void* b)
|
||||
static bool cActionDescending(const device_debug::watchpoint *a, const device_debug::watchpoint *b)
|
||||
{
|
||||
return cActionAscending(b, a);
|
||||
}
|
||||
@ -236,7 +221,7 @@ void debug_view_watchpoints::gather_watchpoints()
|
||||
|
||||
// And now for the sort
|
||||
if (!m_buffer.empty())
|
||||
qsort(&m_buffer[0], m_buffer.size(), sizeof(device_debug::watchpoint *), m_sortType);
|
||||
std::stable_sort(m_buffer.begin(), m_buffer.end(), m_sortType);
|
||||
}
|
||||
|
||||
|
||||
|
@ -43,7 +43,7 @@ private:
|
||||
|
||||
|
||||
// internal state
|
||||
int (*m_sortType)(void const *, void const *);
|
||||
bool (*m_sortType)(const device_debug::watchpoint *, const device_debug::watchpoint *);
|
||||
std::vector<device_debug::watchpoint *> m_buffer;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user