Skip to content

Commit

Permalink
Merge pull request #158 from stof/optimize_next
Browse files Browse the repository at this point in the history
Replace next calls with consume calls when the return value is ignored
  • Loading branch information
goetas committed Nov 26, 2018
2 parents 54d066b + 5309ca3 commit e43f08e
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions src/HTML5/Parser/Tokenizer.php
Expand Up @@ -166,7 +166,7 @@ protected function consumeData()
}

$this->text .= $tok;
$this->scanner->next();
$this->scanner->consume();
}
}
}
Expand Down Expand Up @@ -221,7 +221,7 @@ protected function text($tok)
}

$this->buffer($tok);
$this->scanner->next();
$this->scanner->consume();

return true;
}
Expand Down Expand Up @@ -317,8 +317,8 @@ protected function markupDeclaration($tok)

// Comment:
if ('-' == $tok && '-' == $this->scanner->peek()) {
$this->scanner->next(); // Consume the other '-'
$this->scanner->next(); // Next char.
$this->scanner->consume(2);

return $this->comment();
} elseif ('D' == $tok || 'd' == $tok) { // Doctype
return $this->doctype();
Expand Down Expand Up @@ -369,7 +369,7 @@ protected function endTag()
}

$this->events->endTag($name);
$this->scanner->next();
$this->scanner->consume();

return true;
}
Expand Down Expand Up @@ -407,7 +407,7 @@ protected function tagName()
$this->setTextMode($mode, $name);
}

$this->scanner->next();
$this->scanner->consume();

return true;
}
Expand All @@ -419,7 +419,7 @@ protected function isTagEnd(&$selfClose)
{
$tok = $this->scanner->current();
if ('/' == $tok) {
$this->scanner->next();
$this->scanner->consume();
$this->scanner->whitespace();
$tok = $this->scanner->current();

Expand Down Expand Up @@ -484,7 +484,7 @@ protected function attribute(&$attributes)
// Really, only '=' can be the char here. Everything else gets absorbed
// under one rule or another.
$name = $tok;
$this->scanner->next();
$this->scanner->consume();
}

$isValidAttribute = true;
Expand Down Expand Up @@ -526,7 +526,7 @@ protected function attributeValue()
if ('=' != $this->scanner->current()) {
return null;
}
$this->scanner->next();
$this->scanner->consume();
// 8.1.2.3
$this->scanner->whitespace();

Expand All @@ -540,7 +540,7 @@ protected function attributeValue()
return null;
case '"':
case "'":
$this->scanner->next();
$this->scanner->consume();

return $this->quotedAttributeValue($tok);
case '>':
Expand Down Expand Up @@ -587,7 +587,7 @@ protected function quotedAttributeValue($quote)
}
break;
}
$this->scanner->next();
$this->scanner->consume();

return $val;
}
Expand Down Expand Up @@ -641,7 +641,7 @@ protected function bogusComment($leading = '')

$this->flushBuffer();
$this->events->comment($comment);
$this->scanner->next();
$this->scanner->consume();

return true;
}
Expand All @@ -662,7 +662,7 @@ protected function comment()
// Parse error. Emit the comment token.
$this->parseError("Expected comment data, got '>'");
$this->events->comment('');
$this->scanner->next();
$this->scanner->consume();

return true;
}
Expand All @@ -677,7 +677,7 @@ protected function comment()
}

$this->events->comment($comment);
$this->scanner->next();
$this->scanner->consume();

return true;
}
Expand Down Expand Up @@ -706,7 +706,7 @@ protected function isCommentEnd()

// Advance one, and test for '->'
if ('-' == $this->scanner->next() && '>' == $this->scanner->peek()) {
$this->scanner->next(); // Consume the last '>'
$this->scanner->consume(); // Consume the last '>'
return true;
}
// Unread '-';
Expand Down Expand Up @@ -774,12 +774,12 @@ protected function doctype()
if (0 == strlen($doctypeName)) {
$this->parseError('Expected a DOCTYPE name. Got nothing.');
$this->events->doctype($doctypeName, 0, null, true);
$this->scanner->next();
$this->scanner->consume();

return true;
}
$this->events->doctype($doctypeName);
$this->scanner->next();
$this->scanner->consume();

return true;
}
Expand Down Expand Up @@ -811,7 +811,7 @@ protected function doctype()
$this->scanner->whitespace();
if ('>' == $this->scanner->current()) {
$this->events->doctype($doctypeName, $type, $id, false);
$this->scanner->next();
$this->scanner->consume();

return true;
}
Expand All @@ -821,7 +821,7 @@ protected function doctype()
$this->scanner->charsUntil('>');
$this->parseError('Malformed DOCTYPE.');
$this->events->doctype($doctypeName, $type, $id, true);
$this->scanner->next();
$this->scanner->consume();

return true;
}
Expand All @@ -832,7 +832,7 @@ protected function doctype()

$this->parseError('Expected PUBLIC or SYSTEM. Got %s.', $pub);
$this->events->doctype($doctypeName, 0, null, true);
$this->scanner->next();
$this->scanner->consume();

return true;
}
Expand All @@ -849,10 +849,10 @@ protected function quotedString($stopchars)
{
$tok = $this->scanner->current();
if ('"' == $tok || "'" == $tok) {
$this->scanner->next();
$this->scanner->consume();
$ret = $this->scanner->charsUntil($tok . $stopchars);
if ($this->scanner->current() == $tok) {
$this->scanner->next();
$this->scanner->consume();
} else {
// Parse error because no close quote.
$this->parseError('Expected %s, got %s', $tok, $this->scanner->current());
Expand All @@ -875,7 +875,7 @@ protected function cdataSection()
return false;
}
$cdata = '';
$this->scanner->next();
$this->scanner->consume();

$chars = $this->scanner->charsWhile('CDAT');
if ('CDATA' != $chars || '[' != $this->scanner->current()) {
Expand Down Expand Up @@ -950,8 +950,7 @@ protected function processingInstruction()
}
}

$this->scanner->next(); // >
$this->scanner->next(); // Next token.
$this->scanner->consume(2); // Consume the closing tag
$this->events->processingInstruction($procName, $data);

return true;
Expand Down Expand Up @@ -983,7 +982,7 @@ protected function readUntilSequence($sequence)
return $buffer;
}
$buffer .= $this->scanner->current();
$this->scanner->next();
$this->scanner->consume();
}

// If we get here, we hit the EOF.
Expand Down Expand Up @@ -1160,7 +1159,7 @@ protected function decodeCharacterReference($inAttribute = false)

// We have an entity. We're done here.
if (';' === $tok) {
$this->scanner->next();
$this->scanner->consume();

return $entity;
}
Expand Down

0 comments on commit e43f08e

Please sign in to comment.