* [PATCH 0/2] Two minor cleanups
@ 2022-12-14 19:46 Tom Tromey
2022-12-14 19:46 ` [PATCH 1/2] Remove subset_compare Tom Tromey
2022-12-14 19:46 ` [PATCH 2/2] Move streq and compare_cstrings to gdbsupport Tom Tromey
0 siblings, 2 replies; 4+ messages in thread
From: Tom Tromey @ 2022-12-14 19:46 UTC (permalink / raw)
To: gdb-patches
While digging through util.[ch] I came up with a couple of minor cleanups.
Tom
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] Remove subset_compare
2022-12-14 19:46 [PATCH 0/2] Two minor cleanups Tom Tromey
@ 2022-12-14 19:46 ` Tom Tromey
2022-12-14 19:46 ` [PATCH 2/2] Move streq and compare_cstrings to gdbsupport Tom Tromey
1 sibling, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2022-12-14 19:46 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
I stumbled across subset_compare today, and after looking at the
callers I realized it could be removed and replaced with calls to
startswith.
---
gdb/stack.c | 6 +++---
gdb/tui/tui-win.c | 4 ++--
gdb/utils.c | 20 --------------------
gdb/utils.h | 2 --
4 files changed, 5 insertions(+), 27 deletions(-)
diff --git a/gdb/stack.c b/gdb/stack.c
index 4ad51c2eb50..c7d392842ae 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -2140,17 +2140,17 @@ parse_backtrace_qualifiers (const char *arg,
if (this_arg.empty ())
return arg;
- if (subset_compare (this_arg.c_str (), "no-filters"))
+ if (startswith ("no-filters", this_arg))
{
if (bt_cmd_opts != nullptr)
bt_cmd_opts->no_filters = true;
}
- else if (subset_compare (this_arg.c_str (), "full"))
+ else if (startswith ("full", this_arg))
{
if (bt_cmd_opts != nullptr)
bt_cmd_opts->full = true;
}
- else if (subset_compare (this_arg.c_str (), "hide"))
+ else if (startswith ("hide", this_arg))
{
if (bt_cmd_opts != nullptr)
bt_cmd_opts->hide = true;
diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c
index e24763c0072..bad8ffe0972 100644
--- a/gdb/tui/tui-win.c
+++ b/gdb/tui/tui-win.c
@@ -711,9 +711,9 @@ tui_set_focus_command (const char *arg, int from_tty)
struct tui_win_info *win_info = NULL;
- if (subset_compare (arg, "next"))
+ if (startswith ("next", arg))
win_info = tui_next_win (tui_win_with_focus ());
- else if (subset_compare (arg, "prev"))
+ else if (startswith ("prev", arg))
win_info = tui_prev_win (tui_win_with_focus ());
else
win_info = tui_partial_win_by_name (arg);
diff --git a/gdb/utils.c b/gdb/utils.c
index c37d9add500..5c110daa4ae 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -3109,26 +3109,6 @@ streq (const char *lhs, const char *rhs)
\f
-/*
- ** subset_compare()
- ** Answer whether string_to_compare is a full or partial match to
- ** template_string. The partial match must be in sequence starting
- ** at index 0.
- */
-int
-subset_compare (const char *string_to_compare, const char *template_string)
-{
- int match;
-
- if (template_string != NULL && string_to_compare != NULL
- && strlen (string_to_compare) <= strlen (template_string))
- match =
- (startswith (template_string, string_to_compare));
- else
- match = 0;
- return match;
-}
-
static void
show_debug_timestamp (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
diff --git a/gdb/utils.h b/gdb/utils.h
index d2acf899ba2..ad7c94988b7 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -102,8 +102,6 @@ extern int strcmp_iw_ordered (const char *, const char *);
extern bool streq (const char *, const char *);
-extern int subset_compare (const char *, const char *);
-
/* Compare C strings for std::sort. */
static inline bool
--
2.34.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] Move streq and compare_cstrings to gdbsupport
2022-12-14 19:46 [PATCH 0/2] Two minor cleanups Tom Tromey
2022-12-14 19:46 ` [PATCH 1/2] Remove subset_compare Tom Tromey
@ 2022-12-14 19:46 ` Tom Tromey
2022-12-14 19:51 ` Simon Marchi
1 sibling, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2022-12-14 19:46 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
It seems to me that streq and compare_cstrings belong near the other
string utility functions in common-utils.h; and furthermore that streq
ought to be inlined. This patch makes this change.
---
gdb/utils.c | 8 --------
gdb/utils.h | 12 ------------
gdbsupport/common-utils.h | 16 ++++++++++++++++
3 files changed, 16 insertions(+), 20 deletions(-)
diff --git a/gdb/utils.c b/gdb/utils.c
index 5c110daa4ae..74917f25ab9 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -3099,14 +3099,6 @@ strcmp_iw_ordered (const char *string1, const char *string2)
}
}
-/* See utils.h. */
-
-bool
-streq (const char *lhs, const char *rhs)
-{
- return !strcmp (lhs, rhs);
-}
-
\f
static void
diff --git a/gdb/utils.h b/gdb/utils.h
index ad7c94988b7..509361dc429 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -98,18 +98,6 @@ extern int strcmp_iw (const char *string1, const char *string2);
extern int strcmp_iw_ordered (const char *, const char *);
-/* Return true if the strings are equal. */
-
-extern bool streq (const char *, const char *);
-
-/* Compare C strings for std::sort. */
-
-static inline bool
-compare_cstrings (const char *str1, const char *str2)
-{
- return strcmp (str1, str2) < 0;
-}
-
/* Reset the prompt_for_continue clock. */
void reset_prompt_for_continue_wait_time (void);
/* Return the time spent in prompt_for_continue. */
diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h
index 8a9448a638b..7f5ec584a2e 100644
--- a/gdbsupport/common-utils.h
+++ b/gdbsupport/common-utils.h
@@ -93,6 +93,22 @@ startswith (gdb::string_view string, gdb::string_view pattern)
&& strncmp (string.data (), pattern.data (), pattern.length ()) == 0);
}
+/* Return true if the strings are equal. */
+
+static inline bool
+streq (const char *lhs, const char *rhs)
+{
+ return !strcmp (lhs, rhs);
+}
+
+/* Compare C strings for std::sort. */
+
+static inline bool
+compare_cstrings (const char *str1, const char *str2)
+{
+ return strcmp (str1, str2) < 0;
+}
+
ULONGEST strtoulst (const char *num, const char **trailer, int base);
/* Skip leading whitespace characters in INP, returning an updated
--
2.34.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] Move streq and compare_cstrings to gdbsupport
2022-12-14 19:46 ` [PATCH 2/2] Move streq and compare_cstrings to gdbsupport Tom Tromey
@ 2022-12-14 19:51 ` Simon Marchi
0 siblings, 0 replies; 4+ messages in thread
From: Simon Marchi @ 2022-12-14 19:51 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
> diff --git a/gdbsupport/common-utils.h b/gdbsupport/common-utils.h
> index 8a9448a638b..7f5ec584a2e 100644
> --- a/gdbsupport/common-utils.h
> +++ b/gdbsupport/common-utils.h
> @@ -93,6 +93,22 @@ startswith (gdb::string_view string, gdb::string_view pattern)
> && strncmp (string.data (), pattern.data (), pattern.length ()) == 0);
> }
>
> +/* Return true if the strings are equal. */
> +
> +static inline bool
> +streq (const char *lhs, const char *rhs)
> +{
> + return !strcmp (lhs, rhs);
> +}
While at it, you could maybe change it to
return strcmp (lhs, rhs) == 0;
to make it follow our code convention.
Otherwise, both patches LGTM:
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Simon
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-12-14 19:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-14 19:46 [PATCH 0/2] Two minor cleanups Tom Tromey
2022-12-14 19:46 ` [PATCH 1/2] Remove subset_compare Tom Tromey
2022-12-14 19:46 ` [PATCH 2/2] Move streq and compare_cstrings to gdbsupport Tom Tromey
2022-12-14 19:51 ` 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).