From ae2f3fa7581fb59ebbf80f93b7ed75f853f0ba29 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 4 Nov 2024 10:08:41 -0700 Subject: [PATCH] Turn decode_line_2_compare_items into operator< This rewrites decode_line_2_compare_items to be an operator< on the relevant type. This simplifies the code a little. Reviewed-by: Keith Seitz --- gdb/linespec.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/gdb/linespec.c b/gdb/linespec.c index d5256261eff..4d8a8c1731e 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -1386,6 +1386,14 @@ struct decode_line_2_item { } + /* Used for sorting. */ + bool operator< (const decode_line_2_item &other) const + { + if (displayform != other.displayform) + return displayform < other.displayform; + return fullform < other.fullform; + } + /* The form using symtab_to_fullname. */ std::string fullform; @@ -1397,18 +1405,6 @@ struct decode_line_2_item unsigned int selected : 1; }; -/* Helper for std::sort to sort decode_line_2_item entries by - DISPLAYFORM and secondarily by FULLFORM. */ - -static bool -decode_line_2_compare_items (const decode_line_2_item &a, - const decode_line_2_item &b) -{ - if (a.displayform != b.displayform) - return a.displayform < b.displayform; - return a.fullform < b.fullform; -} - /* Handle multiple results in RESULT depending on SELECT_MODE. This will either return normally, throw an exception on multiple results, or present a menu to the user. On return, the SALS vector @@ -1456,7 +1452,7 @@ decode_line_2 (struct linespec_state *self, } /* Sort the list of method names. */ - std::sort (items.begin (), items.end (), decode_line_2_compare_items); + std::sort (items.begin (), items.end ()); /* Remove entries with the same FULLFORM. */ items.erase (std::unique (items.begin (), items.end (), -- 2.39.5