From 451360ac7e00d3038aa3f4aed3881e5685412f56 Mon Sep 17 00:00:00 2001 From: vlakoff <544424+vlakoff@users.noreply.github.com> Date: Fri, 14 Nov 2025 13:00:03 +0100 Subject: [PATCH 1/2] Remove redundant "& 0xFF" masks from ord() calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These masks were carried over from C-style code, where "& 0xFF" is used to prevent sign-extension when promoting signed chars (-128..127) to ints. In that context, masking ensures the value is treated as an unsigned byte (0..255). In PHP, however, ord() already returns an integer in the range 0–255, making the extra "& 0xFF" operation unnecessary. --- src/Encoder/Encoder.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Encoder/Encoder.php b/src/Encoder/Encoder.php index c363953..10e8a8f 100644 --- a/src/Encoder/Encoder.php +++ b/src/Encoder/Encoder.php @@ -222,7 +222,7 @@ private static function isOnlyDoubleByteKanji(string $content) : bool } for ($i = 0; $i < $length; $i += 2) { - $byte = ord($bytes[$i]) & 0xff; + $byte = ord($bytes[$i]); if (($byte < 0x81 || $byte > 0x9f) && $byte < 0xe0 || $byte > 0xeb) { return false; @@ -649,8 +649,8 @@ private static function appendKanjiBytes(string $content, BitArray $bits) : void $length = strlen($bytes); for ($i = 0; $i < $length; $i += 2) { - $byte1 = ord($bytes[$i]) & 0xff; - $byte2 = ord($bytes[$i + 1]) & 0xff; + $byte1 = ord($bytes[$i]); + $byte2 = ord($bytes[$i + 1]); $code = ($byte1 << 8) | $byte2; if ($code >= 0x8140 && $code <= 0x9ffc) { From 7ae7f05afed0f22bca28c9b1c348721c2ad7af3b Mon Sep 17 00:00:00 2001 From: vlakoff <544424+vlakoff@users.noreply.github.com> Date: Fri, 14 Nov 2025 12:31:51 +0100 Subject: [PATCH 2/2] Remove redundant "& 0xFF" mask in BitArray::generateEcBytes() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The mask was carried over from C-style code, where "& 0xFF" is used to prevent sign-extension when promoting signed chars (-128..127) to ints. In PHP, however, BitArray::toBytes() already produces values in the range 0–255, making the extra mask operation unnecessary. --- src/Encoder/Encoder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Encoder/Encoder.php b/src/Encoder/Encoder.php index 10e8a8f..72ee91f 100644 --- a/src/Encoder/Encoder.php +++ b/src/Encoder/Encoder.php @@ -457,7 +457,7 @@ private static function generateEcBytes(SplFixedArray $dataBytes, int $numEcByte $toEncode = new SplFixedArray($numDataBytes + $numEcBytesInBlock); for ($i = 0; $i < $numDataBytes; $i++) { - $toEncode[$i] = $dataBytes[$i] & 0xff; + $toEncode[$i] = $dataBytes[$i]; } $ecBytes = new SplFixedArray($numEcBytesInBlock);