Skip to content

Commit 7b339b5

Browse files
committed
Optimize the handling of the EOF detection in the main loop
The eof() method is a no-op when the token is not false. As the main loop already needs to identify that case anyway, skipping the method call allows to reduce the cost of parsing text tokens.
1 parent e43f08e commit 7b339b5

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

src/HTML5/Parser/Tokenizer.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ protected function consumeData()
144144
$tok = $this->scanner->current();
145145
}
146146

147-
// Handle end of document
148-
$this->eof($tok);
149-
150-
// Parse character
151-
if (false !== $tok) {
147+
if (false === $tok) {
148+
// Handle end of document
149+
$this->eof();
150+
} else {
151+
// Parse character
152152
switch ($this->textMode) {
153153
case Elements::TEXT_RAW:
154154
$this->rawText($tok);
@@ -290,18 +290,12 @@ protected function rcdata($tok)
290290
/**
291291
* If the document is read, emit an EOF event.
292292
*/
293-
protected function eof($tok)
293+
protected function eof()
294294
{
295-
if (false === $tok) {
296-
// fprintf(STDOUT, "EOF");
297-
$this->flushBuffer();
298-
$this->events->eof();
299-
$this->carryOn = false;
300-
301-
return true;
302-
}
303-
304-
return false;
295+
// fprintf(STDOUT, "EOF");
296+
$this->flushBuffer();
297+
$this->events->eof();
298+
$this->carryOn = false;
305299
}
306300

307301
/**
@@ -744,8 +738,9 @@ protected function doctype()
744738
// EOF: die.
745739
if (false === $tok) {
746740
$this->events->doctype('html5', EventHandler::DOCTYPE_NONE, '', true);
741+
$this->eof();
747742

748-
return $this->eof($tok);
743+
return true;
749744
}
750745

751746
// NULL char: convert.

0 commit comments

Comments
 (0)