public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 2/3] gdb: store interps in an intrusive_list
Date: Fri, 28 Apr 2023 14:27:12 -0400	[thread overview]
Message-ID: <20230428182713.216446-3-simon.marchi@efficios.com> (raw)
In-Reply-To: <20230428182713.216446-1-simon.marchi@efficios.com>

Use intrusive_list, instead of hand-made linked list.

Change-Id: Idc857b40dfa3e3c35671045898331cca2c928097
---
 gdb/interps.c | 18 ++++++------------
 gdb/interps.h |  8 +++-----
 2 files changed, 9 insertions(+), 17 deletions(-)

diff --git a/gdb/interps.c b/gdb/interps.c
index a066c4acfedf..54e1cb45db68 100644
--- a/gdb/interps.c
+++ b/gdb/interps.c
@@ -49,7 +49,7 @@ struct ui_interp_info
   DISABLE_COPY_AND_ASSIGN (ui_interp_info);
 
   /* Each top level has its own independent set of interpreters.  */
-  interp *interp_list = nullptr;
+  intrusive_list<interp> interp_list;
   interp *current_interpreter = nullptr;
   interp *top_level_interpreter = nullptr;
 
@@ -132,8 +132,7 @@ interp_add (struct ui *ui, struct interp *interp)
 
   gdb_assert (interp_lookup_existing (ui, interp->name ()) == NULL);
 
-  interp->next = ui_interp.interp_list;
-  ui_interp.interp_list = interp;
+  ui_interp.interp_list.push_back (*interp);
 }
 
 /* This sets the current interpreter to be INTERP.  If INTERP has not
@@ -204,17 +203,12 @@ static struct interp *
 interp_lookup_existing (struct ui *ui, const char *name)
 {
   ui_interp_info &ui_interp = get_interp_info (ui);
-  struct interp *interp;
 
-  for (interp = ui_interp.interp_list;
-       interp != NULL;
-       interp = interp->next)
-    {
-      if (strcmp (interp->name (), name) == 0)
-	return interp;
-    }
+  for (interp &interp : ui_interp.interp_list)
+    if (strcmp (interp.name (), name) == 0)
+      return &interp;
 
-  return NULL;
+  return nullptr;
 }
 
 /* See interps.h.  */
diff --git a/gdb/interps.h b/gdb/interps.h
index 29248093c671..da78a5d89fae 100644
--- a/gdb/interps.h
+++ b/gdb/interps.h
@@ -22,6 +22,8 @@
 #ifndef INTERPS_H
 #define INTERPS_H
 
+#include "gdbsupport/intrusive_list.h"
+
 struct ui_out;
 struct interp;
 struct ui;
@@ -40,7 +42,7 @@ extern void interp_factory_register (const char *name,
 
 extern void interp_exec (struct interp *interp, const char *command);
 
-class interp
+class interp : public intrusive_list_node<interp>
 {
 public:
   explicit interp (const char *name);
@@ -85,10 +87,6 @@ class interp
   const char *m_name;
 
 public:
-  /* Interpreters are stored in a linked list, this is the next
-     one...  */
-  interp *next = nullptr;
-
   /* Has the init method been run?  */
   bool inited = false;
 };
-- 
2.40.1


  parent reply	other threads:[~2023-04-28 18:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-28 18:27 [PATCH 0/3] Some struct ui / struct interps cleanup Simon Marchi
2023-04-28 18:27 ` [PATCH 1/3] gdb: move struct ui and related things to ui.{c,h} Simon Marchi
2023-04-28 18:27 ` Simon Marchi [this message]
2023-04-28 18:27 ` [PATCH 3/3] gdb: remove ui_interp_info Simon Marchi
2023-05-01 15:25 ` [PATCH 0/3] Some struct ui / struct interps cleanup Tom Tromey
2023-05-02  0:49   ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230428182713.216446-3-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).