From 65c42a6034e810505a2c2481c73c2fa04a45a659 Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Fri, 17 May 2019 16:57:23 +0200 Subject: [PATCH] Simplify a few binary checks for bit 1 ( $var & 1 ) is either 0 or 1, which can be used as a boolean value. The main advantage of this is that there is no confusion with the operator precedence. In `$var & 1 !== 1` the `!==` is executed first, effectively turning it into `$var & 0`. This always succeeds. Change-Id: I53c81a3891d42b2660eefc311f1f0f2523104894 --- includes/diff/DiffEngine.php | 6 +++--- includes/media/DjVuImage.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/diff/DiffEngine.php b/includes/diff/DiffEngine.php index 546a12cb79..ce507d7a83 100644 --- a/includes/diff/DiffEngine.php +++ b/includes/diff/DiffEngine.php @@ -506,13 +506,13 @@ class DiffEngine { // value_to_add_forward: a 0 or 1 that we add to the start // offset to make it odd/even - if ( ( $M & 1 ) == 1 ) { + if ( $M & 1 ) { $value_to_add_forward = 1; } else { $value_to_add_forward = 0; } - if ( ( $N & 1 ) == 1 ) { + if ( $N & 1 ) { $value_to_add_backward = 1; } else { $value_to_add_backward = 0; @@ -530,7 +530,7 @@ class DiffEngine { $V1[$limit_min_1] = $N; $limit = min( $this->maxDifferences, ceil( ( $N + $M ) / 2 ) ); - if ( ( $delta & 1 ) == 1 ) { + if ( $delta & 1 ) { for ( $d = 0; $d <= $limit; ++$d ) { $start_diag = max( $value_to_add_forward + $start_forward, -$d ); $end_diag = min( $end_forward, $d ); diff --git a/includes/media/DjVuImage.php b/includes/media/DjVuImage.php index fde43f404b..13a39edcf2 100644 --- a/includes/media/DjVuImage.php +++ b/includes/media/DjVuImage.php @@ -111,7 +111,7 @@ class DjVuImage { $this->dumpForm( $file, $chunkLength, $indent + 1 ); } else { fseek( $file, $chunkLength, SEEK_CUR ); - if ( ( $chunkLength & 1 ) == 1 ) { + if ( $chunkLength & 1 ) { // Padding byte between chunks fseek( $file, 1, SEEK_CUR ); } @@ -169,7 +169,7 @@ class DjVuImage { private function skipChunk( $file, $chunkLength ) { fseek( $file, $chunkLength, SEEK_CUR ); - if ( ( $chunkLength & 0x01 ) == 1 && !feof( $file ) ) { + if ( ( $chunkLength & 1 ) && !feof( $file ) ) { // padding byte fseek( $file, 1, SEEK_CUR ); } -- 2.20.1