Skip to content

Commit 0444997

Browse files
committed
PHP6616: optimize native function invocation
1 parent b6bf062 commit 0444997

File tree

8 files changed

+39
-39
lines changed

8 files changed

+39
-39
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.28
1+
2.0.29

resources/autoload.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
*
1515
* This file is part of tc-lib-pdf-filter software library.
1616
*/
17-
spl_autoload_register(
17+
\spl_autoload_register(
1818
function ($class) {
1919
$prefix = 'Com\\Tecnick\\';
20-
$len = strlen($prefix);
21-
if (strncmp($prefix, $class, $len) !== 0) {
20+
$len = \strlen($prefix);
21+
if (\strncmp($prefix, $class, $len) !== 0) {
2222
return;
2323
}
24-
$relative_class = substr($class, $len);
25-
$file = dirname(dirname(__DIR__)).'/'.str_replace('\\', '/', $relative_class).'.php';
26-
if (file_exists($file)) {
24+
$relative_class = \substr($class, $len);
25+
$file = \dirname(\dirname(__DIR__)).'/'.\str_replace('\\', '/', $relative_class).'.php';
26+
if (\file_exists($file)) {
2727
require $file;
2828
}
2929
}

src/Type/AsciiEightFive.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,27 @@ public function decode(string $data): string
5252
}
5353

5454
// all white-space characters shall be ignored
55-
$data = preg_replace('/[\s]+/', '', $data);
55+
$data = \preg_replace('/[\s]+/', '', $data);
5656
if ($data === null) {
5757
throw new PPException('invalid code');
5858
}
5959

6060
// check for EOD: 2-character sequence ~> (7Eh)(3Eh)
61-
$eod = strpos($data, '~>');
61+
$eod = \strpos($data, '~>');
6262
if ($eod !== false) {
6363
// remove EOD and following characters (if any)
64-
$data = substr($data, 0, $eod);
64+
$data = \substr($data, 0, $eod);
6565
}
6666

6767
// data length
68-
$data_length = strlen($data);
68+
$data_length = \strlen($data);
6969
// check for invalid characters
70-
if (preg_match('/[^\x21-\x75,\x7A]/', $data) > 0) {
70+
if (\preg_match('/[^\x21-\x75,\x7A]/', $data) > 0) {
7171
throw new PPException('invalid code');
7272
}
7373

7474
// z sequence
75-
$zseq = chr(0) . chr(0) . chr(0) . chr(0);
75+
$zseq = \chr(0) . \chr(0) . \chr(0) . \chr(0);
7676
// position inside a group of 4 bytes (0-3)
7777
$group_pos = 0;
7878
$tuple = 0;
@@ -81,7 +81,7 @@ public function decode(string $data): string
8181
// for each byte
8282
for ($i = 0; $i < $data_length; ++$i) {
8383
// get char value
84-
$char = ord($data[$i]);
84+
$char = \ord($data[$i]);
8585
if ($char == 122) { // 'z'
8686
if ($group_pos == 0) {
8787
$decoded .= $zseq;
@@ -92,7 +92,7 @@ public function decode(string $data): string
9292
// the value represented by a group of 5 characters should never be greater than 2^32 - 1
9393
$tuple += (($char - 33) * $pow85[$group_pos]);
9494
if ($group_pos == 4) {
95-
$decoded .= chr($tuple >> 24) . chr($tuple >> 16) . chr($tuple >> 8) . chr($tuple);
95+
$decoded .= \chr($tuple >> 24) . \chr($tuple >> 16) . \chr($tuple >> 8) . \chr($tuple);
9696
$tuple = 0;
9797
$group_pos = 0;
9898
} else {
@@ -117,9 +117,9 @@ protected function getLastTuple(int $group_pos, int $tuple): string
117117
{
118118
// last tuple (if any)
119119
return match ($group_pos) {
120-
4 => chr($tuple >> 24) . chr($tuple >> 16) . chr($tuple >> 8),
121-
3 => chr($tuple >> 24) . chr($tuple >> 16),
122-
2 => chr($tuple >> 24),
120+
4 => \chr($tuple >> 24) . \chr($tuple >> 16) . \chr($tuple >> 8),
121+
3 => \chr($tuple >> 24) . \chr($tuple >> 16),
122+
2 => \chr($tuple >> 24),
123123
1 => throw new PPException('invalid code'),
124124
default => '',
125125
};

src/Type/AsciiHex.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,38 +50,38 @@ public function decode(string $data): string
5050
}
5151

5252
// all white-space characters shall be ignored
53-
$data = preg_replace('/[\s]+/', '', $data);
53+
$data = \preg_replace('/[\s]+/', '', $data);
5454
if ($data === null) {
5555
throw new PPException('invalid code');
5656
}
5757

5858
// check for EOD character: GREATER-THAN SIGN (3Eh)
59-
$eod = strpos($data, '>');
59+
$eod = \strpos($data, '>');
6060
if ($eod !== false) {
6161
// remove EOD and extra data (if any)
62-
$data = substr($data, 0, $eod);
62+
$data = \substr($data, 0, $eod);
6363
$eod = true;
6464
}
6565

6666
// get data length
67-
$data_length = strlen($data);
67+
$data_length = \strlen($data);
6868
if ($data_length % 2 != 0) {
6969
// odd number of hexadecimal digits
7070
if ($eod) {
7171
// EOD shall behave as if a 0 (zero) followed the last digit
72-
$data = substr($data, 0, -1) . '0' . substr($data, -1);
72+
$data = \substr($data, 0, -1) . '0' . \substr($data, -1);
7373
} else {
7474
throw new PPException('invalid code');
7575
}
7676
}
7777

7878
// check for invalid characters
79-
if (preg_match('/[^a-fA-F\d]/', $data) > 0) {
79+
if (\preg_match('/[^a-fA-F\d]/', $data) > 0) {
8080
throw new PPException('invalid code');
8181
}
8282

8383
// get one byte of binary data for each pair of ASCII hexadecimal digits
84-
$decoded = pack('H*', $data);
84+
$decoded = \pack('H*', $data);
8585
return $decoded;
8686
}
8787
}

src/Type/Flate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function decode(string $data): string
4949
}
5050

5151
// initialize string to return
52-
$decoded = @gzuncompress($data);
52+
$decoded = @\gzuncompress($data);
5353
if ($decoded === false) {
5454
throw new PPException('invalid code');
5555
}

src/Type/Lzw.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,30 +47,30 @@ public function decode(string $data): string
4747
}
4848

4949
// data length
50-
$data_length = strlen($data);
50+
$data_length = \strlen($data);
5151
// convert string to binary string
5252
$bitstring = '';
5353
for ($i = 0; $i < $data_length; ++$i) {
54-
$bitstring .= sprintf('%08b', ord($data[$i]));
54+
$bitstring .= \sprintf('%08b', \ord($data[$i]));
5555
}
5656

5757
// get the number of bits
58-
$data_length = strlen($bitstring);
58+
$data_length = \strlen($bitstring);
5959
// initialize code length in bits
6060
$bitlen = 9;
6161
// initialize dictionary index
6262
$dix = 258;
6363
// initialize the dictionary (with the first 256 entries).
6464
$dictionary = [];
6565
for ($i = 0; $i < 256; ++$i) {
66-
$dictionary[$i] = chr($i);
66+
$dictionary[$i] = \chr($i);
6767
}
6868

6969
// previous val
7070
$prev_index = 0;
7171
$decoded = '';
7272
// while we encounter EOD marker (257), read code_length bits
73-
while (($data_length > 0) && (($index = (int) bindec(substr($bitstring, 0, $bitlen))) != 257)) {
73+
while (($data_length > 0) && (($index = (int) \bindec(\substr($bitstring, 0, $bitlen))) != 257)) {
7474
$this->process($decoded, $bitstring, $bitlen, $data_length, $index, $dictionary, $dix, $prev_index);
7575
}
7676

@@ -93,7 +93,7 @@ protected function process(
9393
int &$prev_index
9494
): void {
9595
// remove read bits from string
96-
$bitstring = substr($bitstring, $bitlen);
96+
$bitstring = \substr($bitstring, $bitlen);
9797
// update number of bits
9898
$data_length -= $bitlen;
9999
if ($index == 256) { // clear-table marker
@@ -105,7 +105,7 @@ protected function process(
105105
// reset the dictionary (with the first 256 entries).
106106
$dictionary = [];
107107
for ($i = 0; $i < 256; ++$i) {
108-
$dictionary[$i] = chr($i);
108+
$dictionary[$i] = \chr($i);
109109
}
110110
} elseif ($prev_index == 256) {
111111
// first entry

src/Type/RunLength.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,24 @@ public function decode(string $data): string
4949
// initialize string to return
5050
$decoded = '';
5151
// data length
52-
$data_length = strlen($data);
52+
$data_length = \strlen($data);
5353
$idx = 0;
5454
while ($idx < $data_length) {
5555
// get current byte value
56-
$byte = ord($data[$idx]);
56+
$byte = \ord($data[$idx]);
5757
if ($byte == 128) {
5858
// a length value of 128 denote EOD
5959
break;
6060
} elseif ($byte < 128) {
6161
// if the length byte is in the range 0 to 127
6262
// the following length + 1 (1 to 128) bytes shall be copied literally during decompression
63-
$decoded .= substr($data, ($idx + 1), ($byte + 1));
63+
$decoded .= \substr($data, ($idx + 1), ($byte + 1));
6464
// move to next block
6565
$idx += ($byte + 2);
6666
} else {
6767
// if length is in the range 129 to 255,
6868
// the following single byte shall be copied 257 - length (2 to 128) times during decompression
69-
$decoded .= str_repeat($data[($idx + 1)], (257 - $byte));
69+
$decoded .= \str_repeat($data[($idx + 1)], (257 - $byte));
7070
// move to next block
7171
$idx += 2;
7272
}

test/FilterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function testAsciiEightFiveEx(): void
102102
{
103103
$this->bcExpectException('\\' . \Com\Tecnick\Pdf\Filter\Exception::class);
104104
$filter = $this->getTestObject();
105-
$filter->decode('ASCII85Decode', chr(254));
105+
$filter->decode('ASCII85Decode', \chr(254));
106106
}
107107

108108
public function testFlate(): void
@@ -123,7 +123,7 @@ public function testFlateEx(): void
123123
public function testRunLength(): void
124124
{
125125
$filter = $this->getTestObject();
126-
$code = chr(247) . 'A' . chr(18) . ' tc-lib-pdf-filter ' . chr(247) . 'B' . chr(128);
126+
$code = \chr(247) . 'A' . \chr(18) . ' tc-lib-pdf-filter ' . \chr(247) . 'B' . \chr(128);
127127
$result = $filter->decode('RunLengthDecode', $code);
128128
$this->assertEquals('AAAAAAAAAA tc-lib-pdf-filter BBBBBBBBBB', $result);
129129
}

0 commit comments

Comments
 (0)