Skip to content

Commit

Permalink
Merge pull request #151 from stof/optimize_character_reference
Browse files Browse the repository at this point in the history
Optimize the handling of references when consuming data
  • Loading branch information
goetas committed Nov 24, 2018
2 parents 9d32f2d + a56b438 commit 855fadd
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions src/HTML5/Parser/Tokenizer.php
Expand Up @@ -121,11 +121,16 @@ public function setTextMode($textmode, $untilTag = null)
*/
protected function consumeData()
{
// Character reference
$this->characterReference();

$tok = $this->scanner->current();

if ($tok === '&') {
// Character reference
$ref = $this->decodeCharacterReference();
$this->buffer($ref);

$tok = $this->scanner->current();
}

// Parse tag
if ($tok === '<') {
// Any buffered text data can go out now.
Expand Down Expand Up @@ -303,25 +308,6 @@ protected function eof($tok)
return false;
}

/**
* Handle character references (aka entities).
*
* This version is specific to PCDATA, as it buffers data into the
* text buffer. For a generic version, see decodeCharacterReference().
*
* HTML5 8.2.4.2
*/
protected function characterReference()
{
if ($this->scanner->current() !== '&') {
return false;
}

$ref = $this->decodeCharacterReference();
$this->buffer($ref);
return true;
}

/**
* Look for markup.
*/
Expand Down

0 comments on commit 855fadd

Please sign in to comment.