From 220cbce9a0e4973eb9744ab9d5d2285af219761d Mon Sep 17 00:00:00 2001 From: "J. King" Date: Fri, 2 Oct 2020 13:50:36 -0400 Subject: [PATCH] Address performance regression in peeking --- lib/Encoding/AbstractEncoding.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Encoding/AbstractEncoding.php b/lib/Encoding/AbstractEncoding.php index 7fbffab..b8206f0 100644 --- a/lib/Encoding/AbstractEncoding.php +++ b/lib/Encoding/AbstractEncoding.php @@ -32,7 +32,7 @@ abstract class AbstractEncoding implements Encoding { /** @var bool $selfSynchronizing Whether the concrete class represents a self-synchronizing decoder. Such decoders do not use the error stack */ protected $selfSynchronizing = false; /** @var string[] $stateProps The list of properties which constitutee state which must be saved when peeking/seeking; some encodings may add to this last for their own purposes */ - protected $stateProps = ["posChar", "posByte", "posErr", "errStack", "errMark", "errSync"]; + protected $stateProps = ["posChar", "posByte", "posErr"]; public $posErr = 0; @@ -164,7 +164,7 @@ abstract class AbstractEncoding implements Encoding { /** Returns a copy of the decoder's state to keep in memory */ protected function stateSave(): array { - $out = []; + $out = ['errCount' => sizeof($this->errStack)]; foreach ($this->stateProps as $prop) { $out[$prop] = $this->$prop; } @@ -173,6 +173,10 @@ abstract class AbstractEncoding implements Encoding { /** Sets the decoder's state to the values specified */ protected function stateApply(array $state) { + while (sizeof($this->errStack) > $state['errCount']) { + list($this->errMark, $this->errSync) = array_pop($this->errStack); + } + unset($state['errCount']); foreach ($state as $key => $value) { $this->$key = $value; }