Skip to content

Conversation

@belisoful
Copy link
Member

I was going through the TBitReader and found this optimization for more compliant masks.

Technically, this shouldn't even be a problem in the code but I want to use the best mask calculation algorithm as an example for others. The problem was collision left shifting 1 by the total number of bits is that the shift would push the bit off.

Instead of (1<<$bits) - 1 it should be ~(-1 << $bits) as this preserves the masking when $bits = PHP_INT_SIZE * 8

@ctrlaltca ctrlaltca merged commit 4fc6c52 into pradosoft:master Apr 30, 2023
@belisoful belisoful deleted the tbithelper-masking branch May 2, 2023 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants