public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Add operator< and operator== to linetable_entry
@ 2023-03-11 15:56 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2023-03-11 15:56 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6e6ac32dde61fd3019b05adaeec372eb16c12bff

commit 6e6ac32dde61fd3019b05adaeec372eb16c12bff
Author: Tom Tromey <tom@tromey.com>
Date:   Tue Mar 7 18:24:14 2023 -0700

    Add operator< and operator== to linetable_entry
    
    This adds a couple of comparison operators to linetable_entry, and
    simplifies both the calls to sort and one other spot that checks for
    equality.
    
    Approved-By: Simon Marchi <simon.marchi@efficios.com>

Diff:
---
 gdb/buildsym.c  | 14 +-------------
 gdb/disasm.c    |  2 +-
 gdb/symtab.h    | 13 +++++++++++++
 gdb/xcoffread.c |  4 +---
 4 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index 712ca4bbd7a..459bc848c67 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -891,25 +891,13 @@ buildsym_compunit::end_compunit_symtab_with_blockvector
     {
       if (!subfile->line_vector_entries.empty ())
 	{
-	  const auto lte_is_less_than
-	    = [] (const linetable_entry &ln1,
-		  const linetable_entry &ln2) -> bool
-	      {
-		if (ln1.pc == ln2.pc
-		    && ((ln1.line == 0) != (ln2.line == 0)))
-		  return ln1.line == 0;
-
-		return (ln1.pc < ln2.pc);
-	      };
-
 	  /* Like the pending blocks, the line table may be scrambled
 	     in reordered executables.  Sort it.  It is important to
 	     preserve the order of lines at the same address, as this
 	     maintains the inline function caller/callee
 	     relationships, this is why std::stable_sort is used.  */
 	  std::stable_sort (subfile->line_vector_entries.begin (),
-			    subfile->line_vector_entries.end (),
-			    lte_is_less_than);
+			    subfile->line_vector_entries.end ());
 	}
 
       /* Allocate a symbol table if necessary.  */
diff --git a/gdb/disasm.c b/gdb/disasm.c
index a0406377acc..49053dcfbad 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -604,7 +604,7 @@ do_mixed_source_and_assembly_deprecated
 
   for (; i < nlines - 1 && le[i].pc < high; i++)
     {
-      if (le[i].line == le[i + 1].line && le[i].pc == le[i + 1].pc)
+      if (le[i] == le[i + 1])
 	continue;		/* Ignore duplicates.  */
 
       /* Skip any end-of-function markers.  */
diff --git a/gdb/symtab.h b/gdb/symtab.h
index c565bc8eac4..69f0eaa0f88 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1547,6 +1547,19 @@ struct rust_vtable_symbol : public symbol
 
 struct linetable_entry
 {
+  bool operator< (const linetable_entry &other) const
+  {
+    if (pc == other.pc
+	&& (line != 0) != (other.line != 0))
+      return line == 0;
+    return pc < other.pc;
+  }
+
+  /* Two entries are equal if they have the same line and PC.  The
+     other members are ignored.  */
+  bool operator== (const linetable_entry &other) const
+  { return line == other.line && pc == other.pc; }
+
   /* The line number for this entry.  */
   int line;
 
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 78aa9539d78..819735d62db 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -439,9 +439,7 @@ arrange_linetable (std::vector<linetable_entry> &old_linetable)
   if (fentries.empty ())
     return;
 
-  std::sort (fentries.begin (), fentries.end (),
-	     [] (const linetable_entry &lte1, const linetable_entry& lte2)
-	     { return lte1.pc < lte2.pc; });
+  std::sort (fentries.begin (), fentries.end ());
 
   /* Allocate a new line table.  */
   std::vector<linetable_entry> new_linetable;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-11 15:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-11 15:56 [binutils-gdb] Add operator< and operator== to linetable_entry Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).