diff options
author | Christian Biesinger <cbiesinger@google.com> | 2019-10-03 00:36:35 -0500 |
---|---|---|
committer | Christian Biesinger <cbiesinger@google.com> | 2019-10-19 15:45:33 -0500 |
commit | 39ef2f6256737db92f5d60fa201fe0b301bb8100 (patch) | |
tree | 13ff1a57f5ecac08df8f0ecdc2f3544cb4d97564 /gdb/breakpoint.c | |
parent | 18338fcee6c75bf0b41f803b84ae15221676f8cd (diff) | |
download | gdb-39ef2f6256737db92f5d60fa201fe0b301bb8100.zip gdb-39ef2f6256737db92f5d60fa201fe0b301bb8100.tar.gz gdb-39ef2f6256737db92f5d60fa201fe0b301bb8100.tar.bz2 |
Replace some more qsort calls with std::sort
This has better typesafety, avoids a function pointer indirection,
and can benefit from inlining.
gdb/ChangeLog:
2019-10-19 Christian Biesinger <cbiesinger@google.com>
* bcache.c (bcache::print_statistics): Use std::sort instead of qsort.
* breakpoint.c (bp_locations_compare): Rename to...
(bp_location_is_less_than): ...this, and change to std::sort semantics.
(update_global_location_list): Use std::sort instead of qsort.
* buildsym.c (compare_line_numbers): Rename to...
(lte_is_less_than): ...this, and change to std::sort semantics.
(buildsym_compunit::end_symtab_with_blockvector): Use std::sort
instead of qsort.
* disasm.c (compare_lines): Rename to...
(line_is_less_than): ...this, and change to std::sort semantics.
(do_mixed_source_and_assembly_deprecated): Call std::sort instead
of qsort.
* dwarf2-frame.c (qsort_fde_cmp): Rename to...
(fde_is_less_than): ...this, and change to std::sort semantics.
(dwarf2_build_frame_info): Call std::sort instead of qsort.
* mdebugread.c (compare_blocks):
(block_is_less_than): ...this, and change to std::sort semantics.
(sort_blocks): Call std::sort instead of qsort.
* objfiles.c (qsort_cmp): Rename to...
(sort_cmp): ...this, and change to std::sort semantics.
(update_section_map): Call std::sort instead of qsort.
* remote.c (compare_pnums): Remove.
(map_regcache_remote_table): Call std::sort instead of qsort.
* utils.c (compare_positive_ints): Remove.
* utils.h (compare_positive_ints): Remove.
* xcoffread.c (compare_lte): Remove.
(arrange_linetable): Call std::sort instead of qsort.
Change-Id: Ibcddce12a3d07448701e731b7150fa23611d86de
Diffstat (limited to 'gdb/breakpoint.c')
-rw-r--r-- | gdb/breakpoint.c | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 2fd2438..c9587ff 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -519,7 +519,7 @@ bool target_exact_watchpoints = false; static struct breakpoint *breakpoint_chain; -/* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */ +/* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */ static struct bp_location **bp_locations; @@ -773,7 +773,7 @@ show_condition_evaluation_mode (struct ui_file *file, int from_tty, /* A comparison function for bp_location AP and BP that is used by bsearch. This comparison function only cares about addresses, unlike - the more general bp_locations_compare function. */ + the more general bp_location_is_less_than function. */ static int bp_locations_compare_addrs (const void *ap, const void *bp) @@ -11428,41 +11428,36 @@ breakpoint_auto_delete (bpstat bs) } /* A comparison function for bp_location AP and BP being interfaced to - qsort. Sort elements primarily by their ADDRESS (no matter what + std::sort. Sort elements primarily by their ADDRESS (no matter what bl_address_is_meaningful says), secondarily by ordering first permanent elements and terciarily just ensuring the array is sorted - stable way despite qsort being an unstable algorithm. */ + stable way despite std::sort being an unstable algorithm. */ static int -bp_locations_compare (const void *ap, const void *bp) +bp_location_is_less_than (const bp_location *a, const bp_location *b) { - const struct bp_location *a = *(const struct bp_location **) ap; - const struct bp_location *b = *(const struct bp_location **) bp; - if (a->address != b->address) - return (a->address > b->address) - (a->address < b->address); + return a->address < b->address; /* Sort locations at the same address by their pspace number, keeping locations of the same inferior (in a multi-inferior environment) grouped. */ if (a->pspace->num != b->pspace->num) - return ((a->pspace->num > b->pspace->num) - - (a->pspace->num < b->pspace->num)); + return a->pspace->num < b->pspace->num; /* Sort permanent breakpoints first. */ if (a->permanent != b->permanent) - return (a->permanent < b->permanent) - (a->permanent > b->permanent); + return a->permanent > b->permanent; /* Make the internal GDB representation stable across GDB runs where A and B memory inside GDB can differ. Breakpoint locations of the same type at the same address can be sorted in arbitrary order. */ if (a->owner->number != b->owner->number) - return ((a->owner->number > b->owner->number) - - (a->owner->number < b->owner->number)); + return a->owner->number < b->owner->number; - return (a > b) - (a < b); + return a < b; } /* Set bp_locations_placed_address_before_address_max and @@ -11677,8 +11672,8 @@ update_global_location_list (enum ugll_insert_mode insert_mode) ALL_BREAKPOINTS (b) for (loc = b->loc; loc; loc = loc->next) *locp++ = loc; - qsort (bp_locations, bp_locations_count, sizeof (*bp_locations), - bp_locations_compare); + std::sort (bp_locations, bp_locations + bp_locations_count, + bp_location_is_less_than); bp_locations_target_extensions_update (); |