Commit 1577f6e6 authored by Tim Düsterhus's avatar Tim Düsterhus
Browse files

Improve performance of the hex encoder

Single bytes can more efficiently be accessed by directly indexing the string.

This also implicitly fixes a bug without any visible effect: `encodeUpper`
retrieved two characters from the bytestring, but only ever used the first.
No related merge requests found
Showing with 2 additions and 2 deletions
+2 -2
......@@ -45,7 +45,7 @@ abstract class Hex implements EncoderInterface
$len = Binary::safeStrlen($binString);
for ($i = 0; $i < $len; ++$i) {
/** @var array<int, int> $chunk */
$chunk = \unpack('C', Binary::safeSubstr($binString, $i, 1));
$chunk = \unpack('C', $binString[$i]);
$c = $chunk[1] & 0xf;
$b = $chunk[1] >> 4;
......@@ -73,7 +73,7 @@ abstract class Hex implements EncoderInterface
for ($i = 0; $i < $len; ++$i) {
/** @var array<int, int> $chunk */
$chunk = \unpack('C', Binary::safeSubstr($binString, $i, 2));
$chunk = \unpack('C', $binString[$i]);
$c = $chunk[1] & 0xf;
$b = $chunk[1] >> 4;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment