Skip to content

Commit

Permalink
Merge pull request #135 from maxmind/greg/remove-runtime-define
Browse files Browse the repository at this point in the history
Remove runtime define of constant
  • Loading branch information
horgh authored Oct 18, 2021
2 parents 83f0765 + 8b2a9f3 commit b1f3c06
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
CHANGELOG
=========

1.10.2
1.11.0
-------------------

* Replace runtime define of a constant to facilitate opcache preloading.
Reported by vedadkajtaz. GitHub #134.
* Resolve minor issue found by the Clang static analyzer in the C
extension.

Expand Down
13 changes: 3 additions & 10 deletions src/MaxMind/Db/Reader/Decoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
// @codingStandardsIgnoreLine
use RuntimeException;

/*
* @ignore
*
* We subtract 1 from the log to protect against precision loss.
*/
\define(__NAMESPACE__ . '\_MM_MAX_INT_BYTES', (int) ((log(\PHP_INT_MAX, 2) - 1) / 8));

class Decoder
{
/**
Expand Down Expand Up @@ -316,11 +309,11 @@ private function decodeUint(string $bytes, int $byteLength)

$integer = 0;

// PHP integers are signed. _MM_MAX_INT_BYTES is the number of
// PHP integers are signed. PHP_INT_SIZE - 1 is the number of
// complete bytes that can be converted to an integer. However,
// we can convert another byte if the leading bit is zero.
$useRealInts = $byteLength <= _MM_MAX_INT_BYTES
|| ($byteLength === _MM_MAX_INT_BYTES + 1 && (\ord($bytes[0]) & 0x80) === 0);
$useRealInts = $byteLength <= \PHP_INT_SIZE - 1
|| ($byteLength === \PHP_INT_SIZE && (\ord($bytes[0]) & 0x80) === 0);

for ($i = 0; $i < $byteLength; ++$i) {
$part = \ord($bytes[$i]);
Expand Down

0 comments on commit b1f3c06

Please sign in to comment.