@matheusbsbs / matheus-bagliano / commits / 2ce6d075fa
Fork 0

use strpbrk(3) to search for characters from a given set

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Feb 22, 2020 at 19:51 UTC 2ce6d075fa35e4ea4a581c809eca3ad5631c9079
4 files changed +4 -5
builtin/show-branch.c
+1 -1
@@ -536,7 +536,7 @@ static void append_one_rev(const char *av)
536 append_ref(av, &revkey, 0);
537 return;
538 }
539 - if (strchr(av, '*') || strchr(av, '?') || strchr(av, '[')) {
539 + if (strpbrk(av, "*?[")) {
540 /* glob style match */
541 int saved_matches = ref_name_cnt;
542
compat/mingw.c
+1 -1
@@ -1232,7 +1232,7 @@ static char *path_lookup(const char *cmd, int exe_only)
1232 int len = strlen(cmd);
1233 int isexe = len >= 4 && !strcasecmp(cmd+len-4, ".exe");
1234
1235 - if (strchr(cmd, '/') || strchr(cmd, '\\'))
1235 + if (strpbrk(cmd, "/\\"))
1236 return xstrdup(cmd);
1237
1238 path = mingw_getenv("PATH");
mailinfo.c
+1 -2
@@ -19,8 +19,7 @@ static void cleanup_space(struct strbuf *sb)
19 static void get_sane_name(struct strbuf *out, struct strbuf *name, struct strbuf *email)
20 {
21 struct strbuf *src = name;
22 - if (name->len < 3 || 60 < name->len || strchr(name->buf, '@') ||
23 - strchr(name->buf, '<') || strchr(name->buf, '>'))
22 + if (name->len < 3 || 60 < name->len || strpbrk(name->buf, "@<>"))
23 src = email;
24 else if (name == out)
25 return;
t/helper/test-windows-named-pipe.c
+1 -1
@@ -19,7 +19,7 @@ int cmd__windows_named_pipe(int argc, const char **argv)
19 if (argc < 2)
20 goto print_usage;
21 filename = argv[1];
22 - if (strchr(filename, '/') || strchr(filename, '\\'))
22 + if (strpbrk(filename, "/\\"))
23 goto print_usage;
24 strbuf_addf(&pathname, "//./pipe/%s", filename);
25