From ad0c43b3974a3d0e94d82e40744008fcfdf2feb9 Mon Sep 17 00:00:00 2001 From: PrinsFrank <25006490+PrinsFrank@users.noreply.github.com> Date: Fri, 17 Jul 2026 19:54:41 +0200 Subject: [PATCH 1/2] Compute strlen of operator once and reuse it --- src/Document/ContentStream/ContentStreamParser.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Document/ContentStream/ContentStreamParser.php b/src/Document/ContentStream/ContentStreamParser.php index 8423f923..45a80319 100644 --- a/src/Document/ContentStream/ContentStreamParser.php +++ b/src/Document/ContentStream/ContentStreamParser.php @@ -98,9 +98,10 @@ public static function parse(array $contentsObjects): ContentStream { $operands .= $previousContentStream->read($startPreviousOperandIndex, $previousContentStream->getSizeInBytes() - $startPreviousOperandIndex); $startPreviousOperandIndex = null; } - $operandLength = $index + 1 - $startCurrentOperandIndex - strlen($operator->value); + $operatorLength = strlen($operator->value); + $operandLength = $index + 1 - $startCurrentOperandIndex - $operatorLength; if ($operandLength > 0) { - $operandEndOffset = $index + 1 - strlen($operator->value); + $operandEndOffset = $index + 1 - $operatorLength; if ($endCommentOffset !== null && $endCommentOffset < $operandEndOffset && $startOfCommentOffset !== null From ba584979661bbb7377ea974c8a0260f7da1ba193 Mon Sep 17 00:00:00 2001 From: PrinsFrank <25006490+PrinsFrank@users.noreply.github.com> Date: Fri, 17 Jul 2026 20:05:20 +0200 Subject: [PATCH 2/2] Replace in_array checks with direct character checks --- src/Document/ContentStream/ContentStreamParser.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Document/ContentStream/ContentStreamParser.php b/src/Document/ContentStream/ContentStreamParser.php index 45a80319..bd966423 100644 --- a/src/Document/ContentStream/ContentStreamParser.php +++ b/src/Document/ContentStream/ContentStreamParser.php @@ -40,7 +40,7 @@ public static function parse(array $contentsObjects): ContentStream { for ($index = 0; $index < $contentStreamSize; $index++) { $char = $contentStream->read($index, 1); if ($inComment === true) { - if (in_array($char, ["\r", "\n"], true)) { + if ($char === "\r" || $char === "\n") { $endCommentOffset = $index + 1; $inComment = false; } @@ -52,7 +52,7 @@ public static function parse(array $contentsObjects): ContentStream { $inStringLiteral = false; } } elseif ($inResourceName === true) { - if (in_array($char, [' ', '<', '(', '/', "\r", "\n"], true) && $previousChar !== '\\') { + if ($previousChar !== '\\' && ($char === ' ' || $char === '<' || $char === '(' || $char === '/' || $char === "\r" || $char === "\n")) { $inResourceName = false; } } elseif ($inDictionary === true) { @@ -150,7 +150,7 @@ public static function getOperator(string $currentChar, ?string $previousChar, ? default => null, }; if ($threeLetterMatch !== null) { - return in_array($thirdToLastChar, ['\\', '/'], true) ? null : $threeLetterMatch; + return ($thirdToLastChar === '\\' || $thirdToLastChar === '/') ? null : $threeLetterMatch; } $twoLetterMatch = match ($previousChar . $currentChar) { @@ -196,7 +196,7 @@ public static function getOperator(string $currentChar, ?string $previousChar, ? default => null, }; if ($twoLetterMatch !== null) { - return in_array($secondToLastChar, ['\\', '/'], true) ? null : $twoLetterMatch; + return ($secondToLastChar === '\\' || $secondToLastChar === '/') ? null : $twoLetterMatch; } $oneLetterMatch = match ($currentChar) { @@ -231,7 +231,7 @@ public static function getOperator(string $currentChar, ?string $previousChar, ? }; if ($oneLetterMatch !== null) { - return in_array($previousChar, ['\\', '/'], true) ? null : $oneLetterMatch; + return ($previousChar === '\\' || $previousChar === '/') ? null : $oneLetterMatch; } return null;