{"thread":{"id":"34131","subject":"[PATCH] use logical OR (||) instead of binary OR (|) in logical context","startedAt":"2013-06-13T18:19:44Z","lastAt":"2013-06-13T18:19:44Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"220762","messageId":"1371147584-31386-1-git-send-email-rene.scharfe@lsrfire.ath.cx","threadId":"34131","inReplyTo":null,"subject":"[PATCH] use logical OR (||) instead of binary OR (|) in logical context","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2013-06-13T18:19:44Z","receivedAt":"2013-06-13T18:19:44Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"The compiler can short-circuit the evaluation of conditions strung\ntogether with logical OR operators instead of computing the resulting\nbitmask with binary ORs.  More importantly, this patch makes the\nintent of the changed code clearer, because the logical context (as\nopposed to binary context) becomes immediately obvious.\n\nWhile we're at it, simplify the check for patch->is_rename in\nbuiltin/apply.c a bit; it can only be 0 or 1, so we don't need a\ncomparison operator.\n\nSigned-off-by: René Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n builtin/apply.c      | 2 +-\n builtin/ls-files.c   | 8 ++++----\n builtin/merge-base.c | 2 +-\n 3 files changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex 30eefc3..faf8e30 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -3525,7 +3525,7 @@ static int check_patch(struct patch *patch)\n \t\tok_if_exists = 0;\n \n \tif (new_name &&\n-\t    ((0 < patch->is_new) | (0 < patch->is_rename) | patch->is_copy)) {\n+\t    ((0 < patch->is_new) || patch->is_rename || patch->is_copy)) {\n \t\tint err = check_to_create(new_name, ok_if_exists);\n \n \t\tif (err && threeway) {\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex 2202072..87f3b33 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -219,7 +219,7 @@ static void show_files(struct dir_struct *dir)\n \t\tif (show_killed)\n \t\t\tshow_killed_files(dir);\n \t}\n-\tif (show_cached | show_stage) {\n+\tif (show_cached || show_stage) {\n \t\tfor (i = 0; i < active_nr; i++) {\n \t\t\tstruct cache_entry *ce = active_cache[i];\n \t\t\tif ((dir->flags & DIR_SHOW_IGNORED) &&\n@@ -233,7 +233,7 @@ static void show_files(struct dir_struct *dir)\n \t\t\t\t(ce_skip_worktree(ce) ? tag_skip_worktree : tag_cached), ce);\n \t\t}\n \t}\n-\tif (show_deleted | show_modified) {\n+\tif (show_deleted || show_modified) {\n \t\tfor (i = 0; i < active_nr; i++) {\n \t\t\tstruct cache_entry *ce = active_cache[i];\n \t\t\tstruct stat st;\n@@ -571,8 +571,8 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)\n \t\tdie(\"ls-files --ignored needs some exclude pattern\");\n \n \t/* With no flags, we default to showing the cached files */\n-\tif (!(show_stage | show_deleted | show_others | show_unmerged |\n-\t      show_killed | show_modified | show_resolve_undo))\n+\tif (!(show_stage || show_deleted || show_others || show_unmerged ||\n+\t      show_killed || show_modified || show_resolve_undo))\n \t\tshow_cached = 1;\n \n \tif (max_prefix)\ndiff --git a/builtin/merge-base.c b/builtin/merge-base.c\nindex 1bc7991..0c4cd2f 100644\n--- a/builtin/merge-base.c\n+++ b/builtin/merge-base.c\n@@ -107,7 +107,7 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)\n \targc = parse_options(argc, argv, prefix, options, merge_base_usage, 0);\n \tif (!octopus && !reduce && argc < 2)\n \t\tusage_with_options(merge_base_usage, options);\n-\tif (is_ancestor && (show_all | octopus | reduce))\n+\tif (is_ancestor && (show_all || octopus || reduce))\n \t\tdie(\"--is-ancestor cannot be used with other options\");\n \tif (is_ancestor)\n \t\treturn handle_is_ancestor(argc, argv);\n-- \n1.8.3\n"}]}