git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] use strpbrk(3) to search for characters from a given set
@ 2020-02-22 18:51 René Scharfe
  2020-02-23  9:01 ` Martin Ågren
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: René Scharfe @ 2020-02-22 18:51 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano

We can check if certain characters are present in a string by calling
strchr(3) on each of them, or we can pass them all to a single
strpbrk(3) call.  The latter is shorter, less repetitive and slightly
more efficient, so let's do that instead.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 builtin/show-branch.c              | 2 +-
 compat/mingw.c                     | 2 +-
 mailinfo.c                         | 3 +--
 t/helper/test-windows-named-pipe.c | 2 +-
 4 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 35d7f51c23..8c90cbb18f 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -536,7 +536,7 @@ static void append_one_rev(const char *av)
 		append_ref(av, &revkey, 0);
 		return;
 	}
-	if (strchr(av, '*') || strchr(av, '?') || strchr(av, '[')) {
+	if (strpbrk(av, "*?[")) {
 		/* glob style match */
 		int saved_matches = ref_name_cnt;

diff --git a/compat/mingw.c b/compat/mingw.c
index b5230149db..d14065d60e 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1245,7 +1245,7 @@ static char *path_lookup(const char *cmd, int exe_only)
 	int len = strlen(cmd);
 	int isexe = len >= 4 && !strcasecmp(cmd+len-4, ".exe");

-	if (strchr(cmd, '/') || strchr(cmd, '\\'))
+	if (strpbrk(cmd, "/\\"))
 		return xstrdup(cmd);

 	path = mingw_getenv("PATH");
diff --git a/mailinfo.c b/mailinfo.c
index cf92255515..742fa376ab 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -19,8 +19,7 @@ static void cleanup_space(struct strbuf *sb)
 static void get_sane_name(struct strbuf *out, struct strbuf *name, struct strbuf *email)
 {
 	struct strbuf *src = name;
-	if (name->len < 3 || 60 < name->len || strchr(name->buf, '@') ||
-		strchr(name->buf, '<') || strchr(name->buf, '>'))
+	if (name->len < 3 || 60 < name->len || strpbrk(name->buf, "@<>"))
 		src = email;
 	else if (name == out)
 		return;
diff --git a/t/helper/test-windows-named-pipe.c b/t/helper/test-windows-named-pipe.c
index b4b752b01a..ae52183e63 100644
--- a/t/helper/test-windows-named-pipe.c
+++ b/t/helper/test-windows-named-pipe.c
@@ -19,7 +19,7 @@ int cmd__windows_named_pipe(int argc, const char **argv)
 	if (argc < 2)
 		goto print_usage;
 	filename = argv[1];
-	if (strchr(filename, '/') || strchr(filename, '\\'))
+	if (strpbrk(filename, "/\\"))
 		goto print_usage;
 	strbuf_addf(&pathname, "//./pipe/%s", filename);

--
2.25.1

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

end of thread, other threads:[~2020-02-24 19:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-22 18:51 [PATCH] use strpbrk(3) to search for characters from a given set René Scharfe
2020-02-23  9:01 ` Martin Ågren
2020-02-24  6:38 ` Jeff King
2020-02-24 17:10 ` Junio C Hamano
2020-02-24 19:01   ` René Scharfe
2020-02-24 19:10     ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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