From e3f33eaddfc44c53c14711c251fda851f3ca67da Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 20 Mar 2021 21:47:14 +0100 Subject: [PATCH] performance take1: use array access for non multibyte string offsets --- src/StringStream.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/StringStream.php b/src/StringStream.php index aaf10e2..9e053f6 100644 --- a/src/StringStream.php +++ b/src/StringStream.php @@ -39,7 +39,12 @@ public function take1(): TakeResult { $this->guardEndOfStream(); - $token = mb_substr($this->string, 0, 1); + $ord = \ord($this->string[0]); + if ($ord < 128) { + $token = $this->string[0]; + } else { + $token = mb_substr($this->string, 0, 1); + } $position = $this->position->advance($token); return new TakeResult(