diff options
author | Christophe Coevoet <[email protected]> | 2018-11-24 23:02:42 +0100 |
---|---|---|
committer | Christophe Coevoet <[email protected]> | 2018-11-26 19:11:44 +0100 |
commit | 6cdf4283046325b9bc2671d0648b73a2be1d0946 (patch) | |
tree | 6b325a7b6fc3a9f422446af9dc9e1667e6aeb82c /src/HTML5 | |
parent | 1e58def01d8ef2ee773a989b7f738f232088a674 (diff) |
Optimize the main loop
Diffstat (limited to 'src/HTML5')
-rw-r--r-- | src/HTML5/Parser/Tokenizer.php | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/src/HTML5/Parser/Tokenizer.php b/src/HTML5/Parser/Tokenizer.php index 9f3d7bd..c2abb4f 100644 --- a/src/HTML5/Parser/Tokenizer.php +++ b/src/HTML5/Parser/Tokenizer.php @@ -133,13 +133,19 @@ class Tokenizer $tok = $this->scanner->next(); - $this->markupDeclaration($tok) - || $this->endTag() - || $this->processingInstruction() - || $this->tagName() - // This always returns false. - || $this->parseError('Illegal tag opening') - || $this->characterData(); + if ('!' === $tok) { + $this->markupDeclaration(); + } elseif ('/' === $tok) { + $this->endTag(); + } elseif ('?' === $tok) { + $this->processingInstruction(); + } elseif (ctype_alpha($tok)) { + $this->tagName(); + } else { + $this->parseError('Illegal tag opening'); + // TODO is this necessary ? + $this->characterData(); + } $tok = $this->scanner->current(); } @@ -301,12 +307,8 @@ class Tokenizer /** * Look for markup. */ - protected function markupDeclaration($tok) + protected function markupDeclaration() { - if ('!' != $tok) { - return false; - } - $tok = $this->scanner->next(); // Comment: @@ -373,11 +375,6 @@ class Tokenizer */ protected function tagName() { - $tok = $this->scanner->current(); - if (!ctype_alpha($tok)) { - return false; - } - // We know this is at least one char. $name = $this->scanner->charsWhile(':_-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'); $name = self::CONFORMANT_XML === $this->mode ? $name : strtolower($name); @@ -790,7 +787,7 @@ class Tokenizer if (false === $id) { $this->events->doctype($doctypeName, $type, $pub, false); - return false; + return true; } // Premature EOF. |