Skip to content

Commit

Permalink
Merge pull request #154 from stof/optimize_token_comparison
Browse files Browse the repository at this point in the history
Optimize the token comparison
  • Loading branch information
goetas committed Nov 26, 2018
2 parents e43f08e + 89e1a7a commit 3ed3bdc
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/HTML5/Parser/Tokenizer.php
Expand Up @@ -47,8 +47,6 @@ class Tokenizer
const CONFORMANT_HTML = 'html';
protected $mode = self::CONFORMANT_HTML;

const WHITE = "\t\n\f ";

/**
* Create a new tokenizer.
*
Expand Down Expand Up @@ -159,7 +157,7 @@ protected function consumeData()
break;

default:
if (!strspn($tok, '<&')) {
if ('<' !== $tok && '&' !== $tok) {
// NULL character
if ("\00" === $tok) {
$this->parseError('Received null character.');
Expand Down Expand Up @@ -193,7 +191,7 @@ protected function characterData()
case Elements::TEXT_RCDATA:
return $this->rcdata($tok);
default:
if (strspn($tok, '<&')) {
if ('<' === $tok || '&' === $tok) {
return false;
}

Expand Down Expand Up @@ -1092,7 +1090,7 @@ protected function decodeCharacterReference($inAttribute = false)

// These indicate not an entity. We return just
// the &.
if (1 === strspn($tok, static::WHITE . '&<')) {
if ("\t" === $tok || "\n" === $tok || "\f" === $tok || ' ' === $tok || '&' === $tok || '<' === $tok) {
// $this->scanner->next();
return '&';
}
Expand Down

0 comments on commit 3ed3bdc

Please sign in to comment.