refactor: remove redundant "& 0xFF" masks from ord() and BitArray#203
Merged
DASPRiD merged 2 commits intoBacon:mainfrom Nov 16, 2025
Merged
refactor: remove redundant "& 0xFF" masks from ord() and BitArray#203DASPRiD merged 2 commits intoBacon:mainfrom
DASPRiD merged 2 commits intoBacon:mainfrom
Conversation
Member
|
Please rebase against main to get the tests working. |
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.
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.
a738de6 to
7ae7f05
Compare
Contributor
Author
|
Rebased. Please let me know what you would like to see improved (including commit messages) before considering this for merging. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #203 +/- ##
=========================================
Coverage 70.58% 70.58%
Complexity 995 995
=========================================
Files 49 49
Lines 3182 3182
=========================================
Hits 2246 2246
Misses 936 936 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
|
LGTM, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change removes unnecessary bitmask operations that were carried over from C-style code:
& 0xFFis used to prevent sign-extension when promoting signed chars (-128..127) to ints, ensuring values are treated as unsigned bytes (0..255).ord()already returns integers in the range0–255, so applying& 0xFFis redundant.BitArray::toBytes()produces values in the correct range, making the extra mask inBitArray::generateEcBytes()unnecessary.This simplifies the codebase and makes the implementation more idiomatic to PHP.