Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 4/6] Remove sentinel from remote_fio_func_map
Date: Sun, 31 Dec 2023 13:25:41 -0700	[thread overview]
Message-ID: <20231231-remote-fileio-v1-4-249cc6c440d9@tromey.com> (raw)
In-Reply-To: <20231231-remote-fileio-v1-0-249cc6c440d9@tromey.com>

With foreach, a static array like remote_fio_func_map does not need a
sentinel entry.  This patch removes it and slightly rearranges the
code to suit.
---
 gdb/remote-fileio.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c
index f6990989da6..e001c220522 100644
--- a/gdb/remote-fileio.c
+++ b/gdb/remote-fileio.c
@@ -1154,11 +1154,9 @@ remote_fileio_data::do_request (remote_target *remote, char *buf)
     { "gettimeofday", &remote_fileio_data::func_gettimeofday },
     { "isatty", &remote_fileio_data::func_isatty },
     { "system", &remote_fileio_data::func_system },
-    { nullptr, nullptr }
   };
 
   char *c;
-  int idx;
 
   quit_handler = remote_fileio_quit_handler;
 
@@ -1167,13 +1165,14 @@ remote_fileio_data::do_request (remote_target *remote, char *buf)
     *c++ = '\0';
   else
     c = strchr (buf, '\0');
-  for (idx = 0; remote_fio_func_map[idx].name; ++idx)
-    if (!strcmp (remote_fio_func_map[idx].name, buf))
-      break;
-  if (!remote_fio_func_map[idx].name)
-    remote_fileio_reply (remote, -1, FILEIO_ENOSYS);
-  else
-    (this->*remote_fio_func_map[idx].func) (remote, c);
+  for (const auto &entry : remote_fio_func_map)
+    if (!strcmp (entry.name, buf))
+      {
+	(this->*entry.func) (remote, c);
+	return;
+      }
+	
+  remote_fileio_reply (remote, -1, FILEIO_ENOSYS);
 }
 
 /* Close any open descriptors, and reinitialize the file mapping.  */

-- 
2.43.0


  parent reply	other threads:[~2023-12-31 20:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-31 20:25 [PATCH 0/6] Make remote-fileio per-target Tom Tromey
2023-12-31 20:25 ` [PATCH 1/6] Make remote_fio_func_map 'const' Tom Tromey
2023-12-31 20:25 ` [PATCH 2/6] Use vector in remote-fileio.c Tom Tromey
2024-01-01 14:20   ` Lancelot SIX
2024-01-01 18:39     ` Simon Marchi
2023-12-31 20:25 ` [PATCH 3/6] Use methods for remote fileio Tom Tromey
2023-12-31 20:25 ` Tom Tromey [this message]
2023-12-31 20:25 ` [PATCH 5/6] Move remote_fileio_data to header file Tom Tromey
2023-12-31 20:25 ` [PATCH 6/6] Store remote fileio state in remote_state Tom Tromey
2024-01-01 14:28 ` [PATCH 0/6] Make remote-fileio per-target Lancelot SIX

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=20231231-remote-fileio-v1-4-249cc6c440d9@tromey.com \
    --to=tom@tromey.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