public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Use iterator_range in more places
@ 2021-07-29 22:08 Tom Tromey
  2021-07-30  2:18 ` Simon Marchi
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2021-07-29 22:08 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes a couple of spots to replace custom iterator range
classes with a specialization of iterator_range.

Regression tested on x86-64 Fedora 34.
---
 gdb/objfiles.h | 59 ++++++++------------------------------------------
 1 file changed, 9 insertions(+), 50 deletions(-)

diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 55be1bfdda4..97abc9c17ef 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -380,29 +380,7 @@ class separate_debug_iterator
 
 /* A range adapter wrapping separate_debug_iterator.  */
 
-class separate_debug_range
-{
-public:
-
-  explicit separate_debug_range (struct objfile *objfile)
-    : m_objfile (objfile)
-  {
-  }
-
-  separate_debug_iterator begin ()
-  {
-    return separate_debug_iterator (m_objfile);
-  }
-
-  separate_debug_iterator end ()
-  {
-    return separate_debug_iterator (nullptr);
-  }
-
-private:
-
-  struct objfile *m_objfile;
-};
+typedef iterator_range<separate_debug_iterator> separate_debug_range;
 
 /* Master structure for keeping track of each file from which
    gdb reads symbols.  There are several ways these get allocated: 1.
@@ -456,38 +434,17 @@ struct objfile
   /* A range adapter that makes it possible to iterate over all
      minimal symbols of an objfile.  */
 
-  class msymbols_range
-  {
-  public:
-
-    explicit msymbols_range (struct objfile *objfile)
-      : m_objfile (objfile)
-    {
-    }
-
-    minimal_symbol_iterator begin () const
-    {
-      return minimal_symbol_iterator (m_objfile->per_bfd->msymbols.get ());
-    }
-
-    minimal_symbol_iterator end () const
-    {
-      return minimal_symbol_iterator
-	(m_objfile->per_bfd->msymbols.get ()
-	 + m_objfile->per_bfd->minimal_symbol_count);
-    }
-
-  private:
-
-    struct objfile *m_objfile;
-  };
+  typedef iterator_range<minimal_symbol_iterator> msymbols_range;
 
   /* Return a range adapter for iterating over all minimal
      symbols.  */
 
   msymbols_range msymbols ()
   {
-    return msymbols_range (this);
+    auto start = minimal_symbol_iterator (per_bfd->msymbols.get ());
+    auto end = minimal_symbol_iterator (per_bfd->msymbols.get ()
+					+ per_bfd->minimal_symbol_count);
+    return msymbols_range (start, end);
   }
 
   /* Return a range adapter for iterating over all the separate debug
@@ -495,7 +452,9 @@ struct objfile
 
   separate_debug_range separate_debug_objfiles ()
   {
-    return separate_debug_range (this);
+    auto start = separate_debug_iterator (this);
+    auto end = separate_debug_iterator (nullptr);
+    return separate_debug_range (start, end);
   }
 
   CORE_ADDR text_section_offset () const
-- 
2.31.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Use iterator_range in more places
  2021-07-29 22:08 [PATCH] Use iterator_range in more places Tom Tromey
@ 2021-07-30  2:18 ` Simon Marchi
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2021-07-30  2:18 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches



On 2021-07-29 6:08 p.m., Tom Tromey wrote:
> This changes a couple of spots to replace custom iterator range
> classes with a specialization of iterator_range.

LGTM, thanks.  I'm glad this is useful.

Simon

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-30  2:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-29 22:08 [PATCH] Use iterator_range in more places Tom Tromey
2021-07-30  2:18 ` Simon Marchi

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).