From f20b2fcf33c6f328be80b58fb48bf912843d68d3 Mon Sep 17 00:00:00 2001 From: Julian Date: Sat, 30 Nov 2013 19:30:52 +0100 Subject: [PATCH] Small lexer optimisation using the \G assertion. --- Llk/Lexer.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Llk/Lexer.php b/Llk/Lexer.php index 2a4be53c..38117218 100644 --- a/Llk/Lexer.php +++ b/Llk/Lexer.php @@ -260,14 +260,14 @@ protected function matchLexeme ( $lexeme, $regex, $offset ) { $_regex = str_replace('#', '\#', $regex); $preg = preg_match( - '#(?|' . $_regex . ')#u', + '#\G(?|' . $_regex . ')#u', $this->_text, $matches, - PREG_OFFSET_CAPTURE, + 0, $offset ); - if(0 === $preg || $offset !== $matches[0][1]) + if(0 === $preg) return null; if('' === $matches[0]) @@ -277,8 +277,8 @@ protected function matchLexeme ( $lexeme, $regex, $offset ) { return array( 'token' => $lexeme, - 'value' => $matches[0][0], - 'length' => mb_strlen($matches[0][0]) + 'value' => $matches[0], + 'length' => mb_strlen($matches[0]) ); } }