Skip to content

Commit 2ce6d07

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2b3c430 commit 2ce6d07

File tree

4 files changed

+4
-5
lines changed

4 files changed

+4
-5
lines changed

builtin/show-branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ static void append_one_rev(const char *av)
536536
append_ref(av, &revkey, 0);
537537
return;
538538
}
539-
if (strchr(av, '*') || strchr(av, '?') || strchr(av, '[')) {
539+
if (strpbrk(av, "*?[")) {
540540
/* glob style match */
541541
int saved_matches = ref_name_cnt;
542542

compat/mingw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ static char *path_lookup(const char *cmd, int exe_only)
12321232
int len = strlen(cmd);
12331233
int isexe = len >= 4 && !strcasecmp(cmd+len-4, ".exe");
12341234

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

12381238
path = mingw_getenv("PATH");

mailinfo.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ static void cleanup_space(struct strbuf *sb)
1919
static void get_sane_name(struct strbuf *out, struct strbuf *name, struct strbuf *email)
2020
{
2121
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, "@<>"))
2423
src = email;
2524
else if (name == out)
2625
return;

t/helper/test-windows-named-pipe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ int cmd__windows_named_pipe(int argc, const char **argv)
1919
if (argc < 2)
2020
goto print_usage;
2121
filename = argv[1];
22-
if (strchr(filename, '/') || strchr(filename, '\\'))
22+
if (strpbrk(filename, "/\\"))
2323
goto print_usage;
2424
strbuf_addf(&pathname, "//./pipe/%s", filename);
2525

0 commit comments

Comments
 (0)