]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Turn decode_line_2_compare_items into operator<
authorTom Tromey <tromey@adacore.com>
Mon, 4 Nov 2024 17:08:41 +0000 (10:08 -0700)
committerTom Tromey <tromey@adacore.com>
Mon, 4 Nov 2024 19:56:57 +0000 (12:56 -0700)
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 <keiths@redhat.com>
gdb/linespec.c

index d5256261eff5c71f82652be02e7a0e0774a80512..4d8a8c1731e19a400f026e20239be246e53093fc 100644 (file)
@@ -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 (),