From a0bf8a9b0533edeeeb07457483bf4dcbbe21ef8a Mon Sep 17 00:00:00 2001 From: "J. King" Date: Thu, 30 Aug 2018 08:55:33 -0400 Subject: [PATCH] Don't check for dirty EOF on every iteration --- lib/Encoding/GBCommon.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/Encoding/GBCommon.php b/lib/Encoding/GBCommon.php index 108c13b..0d6328f 100644 --- a/lib/Encoding/GBCommon.php +++ b/lib/Encoding/GBCommon.php @@ -148,14 +148,15 @@ abstract class GBCommon implements StatelessEncoding { /** Implements backward seeking $distance characters */ protected function seekBack(int $distance): int { + if ($this->posByte >= $this->lenByte && $this->dirtyEOF > 0) { + // if we are at the end of the string and it did not terminate cleanly, go back the correct number of dirty bytes to seek through the last character + $this->posByte -= $this->dirtyEOF; + $distance--; + $this->posChar--; + } while ($distance > 0 && $this->posByte > 0) { $distance--; $this->posChar--; - if ($this->posByte == $this->lenByte && $this->dirtyEOF > 0) { - // if we are at the end of the string and it did not terminate cleanly, go back the correct number of dirty bytes to seek through the last character - $this->posByte -= $this->dirtyEOF; - continue; - } // go back one byte $b1 = ord(@$this->string[--$this->posByte]); if ($b1 < 0x30 || $b1 == 0x7F || $this->posByte == 0) { // these bytes never appear in sequences, and the first byte is necessarily the start of a sequence