From 2ce6d075fa35e4ea4a581c809eca3ad5631c9079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Sat, 22 Feb 2020 19:51:19 +0100 Subject: use strpbrk(3) to search for characters from a given set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano diff --git a/builtin/show-branch.c b/builtin/show-branch.c index 35d7f51..8c90cbb 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 402c1ad..7ec6c04 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1232,7 +1232,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 b395adb..eeef190 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 b4b752b..ae52183 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); -- cgit v0.10.2-6-g49f6