Skip to content

Commit b1f3c06

Browse files
authored
Merge pull request #135 from maxmind/greg/remove-runtime-define
Remove runtime define of constant
2 parents 83f0765 + 8b2a9f3 commit b1f3c06

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
CHANGELOG
22
=========
33

4-
1.10.2
4+
1.11.0
55
-------------------
66

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

src/MaxMind/Db/Reader/Decoder.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@
77
// @codingStandardsIgnoreLine
88
use RuntimeException;
99

10-
/*
11-
* @ignore
12-
*
13-
* We subtract 1 from the log to protect against precision loss.
14-
*/
15-
\define(__NAMESPACE__ . '\_MM_MAX_INT_BYTES', (int) ((log(\PHP_INT_MAX, 2) - 1) / 8));
16-
1710
class Decoder
1811
{
1912
/**
@@ -316,11 +309,11 @@ private function decodeUint(string $bytes, int $byteLength)
316309

317310
$integer = 0;
318311

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

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

0 commit comments

Comments
 (0)