Skip to content

Commit 0b437a1

Browse files
René Scharfegitster
authored andcommitted
use logical OR (||) instead of binary OR (|) in logical context
The compiler can short-circuit the evaluation of conditions strung together with logical OR operators instead of computing the resulting bitmask with binary ORs. More importantly, this patch makes the intent of the changed code clearer, because the logical context (as opposed to binary context) becomes immediately obvious. While we're at it, simplify the check for patch->is_rename in builtin/apply.c a bit; it can only be 0 or 1, so we don't need a comparison operator. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f2b4626 commit 0b437a1

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

builtin/apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3525,7 +3525,7 @@ static int check_patch(struct patch *patch)
35253525
ok_if_exists = 0;
35263526

35273527
if (new_name &&
3528-
((0 < patch->is_new) | (0 < patch->is_rename) | patch->is_copy)) {
3528+
((0 < patch->is_new) || patch->is_rename || patch->is_copy)) {
35293529
int err = check_to_create(new_name, ok_if_exists);
35303530

35313531
if (err && threeway) {

builtin/ls-files.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ static void show_files(struct dir_struct *dir)
219219
if (show_killed)
220220
show_killed_files(dir);
221221
}
222-
if (show_cached | show_stage) {
222+
if (show_cached || show_stage) {
223223
for (i = 0; i < active_nr; i++) {
224224
struct cache_entry *ce = active_cache[i];
225225
if ((dir->flags & DIR_SHOW_IGNORED) &&
@@ -233,7 +233,7 @@ static void show_files(struct dir_struct *dir)
233233
(ce_skip_worktree(ce) ? tag_skip_worktree : tag_cached), ce);
234234
}
235235
}
236-
if (show_deleted | show_modified) {
236+
if (show_deleted || show_modified) {
237237
for (i = 0; i < active_nr; i++) {
238238
struct cache_entry *ce = active_cache[i];
239239
struct stat st;
@@ -571,8 +571,8 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
571571
die("ls-files --ignored needs some exclude pattern");
572572

573573
/* With no flags, we default to showing the cached files */
574-
if (!(show_stage | show_deleted | show_others | show_unmerged |
575-
show_killed | show_modified | show_resolve_undo))
574+
if (!(show_stage || show_deleted || show_others || show_unmerged ||
575+
show_killed || show_modified || show_resolve_undo))
576576
show_cached = 1;
577577

578578
if (max_prefix)

builtin/merge-base.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)
107107
argc = parse_options(argc, argv, prefix, options, merge_base_usage, 0);
108108
if (!octopus && !reduce && argc < 2)
109109
usage_with_options(merge_base_usage, options);
110-
if (is_ancestor && (show_all | octopus | reduce))
110+
if (is_ancestor && (show_all || octopus || reduce))
111111
die("--is-ancestor cannot be used with other options");
112112
if (is_ancestor)
113113
return handle_is_ancestor(argc, argv);

0 commit comments

Comments
 (0)