forked from Imagelibrary/binutils-gdb
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
This commit is contained in:
@@ -68,6 +68,8 @@
|
||||
|
||||
#include "expression.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
/* Provide a way to test if we have both ECOFF and ELF symbol tables.
|
||||
We use this define in order to know whether we should override a
|
||||
symbol's ECOFF section with its ELF section. This is necessary in
|
||||
@@ -4560,17 +4562,16 @@ add_line (struct linetable *lt, int lineno, CORE_ADDR adr, int last)
|
||||
|
||||
/* Blocks with a smaller low bound should come first. */
|
||||
|
||||
static int
|
||||
compare_blocks (const void *arg1, const void *arg2)
|
||||
static bool
|
||||
block_is_less_than (const struct block *b1, const struct block *b2)
|
||||
{
|
||||
LONGEST addr_diff;
|
||||
struct block **b1 = (struct block **) arg1;
|
||||
struct block **b2 = (struct block **) arg2;
|
||||
CORE_ADDR start1 = BLOCK_START (b1);
|
||||
CORE_ADDR start2 = BLOCK_START (b2);
|
||||
|
||||
addr_diff = (BLOCK_START ((*b1))) - (BLOCK_START ((*b2)));
|
||||
if (addr_diff == 0)
|
||||
return (BLOCK_END ((*b2))) - (BLOCK_END ((*b1)));
|
||||
return addr_diff;
|
||||
if (start1 != start2)
|
||||
return start1 < start2;
|
||||
|
||||
return (BLOCK_END (b2)) < (BLOCK_END (b1));
|
||||
}
|
||||
|
||||
/* Sort the blocks of a symtab S.
|
||||
@@ -4600,10 +4601,9 @@ sort_blocks (struct symtab *s)
|
||||
* to detect -O3 images in advance.
|
||||
*/
|
||||
if (BLOCKVECTOR_NBLOCKS (bv) > FIRST_LOCAL_BLOCK + 1)
|
||||
qsort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK),
|
||||
BLOCKVECTOR_NBLOCKS (bv) - FIRST_LOCAL_BLOCK,
|
||||
sizeof (struct block *),
|
||||
compare_blocks);
|
||||
std::sort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK),
|
||||
&BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)),
|
||||
block_is_less_than);
|
||||
|
||||
{
|
||||
CORE_ADDR high = 0;
|
||||
|
||||
Reference in New Issue
Block a user