Skip to content

Commit d7afca0

Browse files
committed
Always use preincrement operator
Especially when these functions are being called hundreds of thousands of times during a parse, preincrementing absolutely is a noticeable performance boost.
1 parent 8457832 commit d7afca0

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lib/Sabberworm/CSS/Parser.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ private function parseCharacter($bIsForIdentifier) {
223223
}
224224
$iUnicode = intval($sUnicode, 16);
225225
$sUtf32 = "";
226-
for ($i = 0; $i < 4; $i++) {
226+
for ($i = 0; $i < 4; ++$i) {
227227
$sUtf32 .= chr($iUnicode & 0xff);
228228
$iUnicode = $iUnicode >> 8;
229229
}
@@ -268,7 +268,7 @@ private function parseRuleSet($oRuleSet) {
268268
$sConsume = $this->consumeUntil(array("\n", ";", '}'), true);
269269
// We need to “unfind” the matches to the end of the ruleSet as this will be matched later
270270
if($this->streql($this->substr($sConsume, $this->strlen($sConsume)-1, 1), '}')) {
271-
$this->iCurrentPosition--;
271+
--$this->iCurrentPosition;
272272
} else {
273273
$this->consumeWhiteSpace();
274274
while ($this->comes(';')) {
@@ -341,11 +341,10 @@ private function parseValue($aListDelimiters) {
341341
$iStartPosition = null;
342342
while (($iStartPosition = array_search($sDelimiter, $aStack, true)) !== false) {
343343
$iLength = 2; //Number of elements to be joined
344-
for ($i = $iStartPosition + 2; $i < count($aStack); $i+=2) {
344+
for ($i = $iStartPosition + 2; $i < count($aStack); $i+=2, ++$iLength) {
345345
if ($sDelimiter !== $aStack[$i]) {
346346
break;
347347
}
348-
$iLength++;
349348
}
350349
$oList = new RuleValueList($sDelimiter);
351350
for ($i = $iStartPosition - 1; $i - $iStartPosition + 1 < $iLength * 2; $i+=2) {
@@ -420,7 +419,7 @@ private function parseColorValue() {
420419
$this->consumeWhiteSpace();
421420
$this->consume('(');
422421
$iLength = $this->strlen($sColorMode);
423-
for ($i = 0; $i < $iLength; $i++) {
422+
for ($i = 0; $i < $iLength; ++$i) {
424423
$this->consumeWhiteSpace();
425424
$aColor[$sColorMode[$i]] = $this->parseNumericValue(true);
426425
$this->consumeWhiteSpace();

0 commit comments

Comments
 (0)