Skip to content

Commit e7ef7a8

Browse files
committed
Optimize identifierIs()
No reason for this method to be static Optimize for the most-expected case - a non-prefixed identifier.
1 parent 3e4e892 commit e7ef7a8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/Sabberworm/CSS/Parser.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private function parseAtRule() {
107107
$this->consume(';');
108108
$this->setCharset($sCharset->getString());
109109
return new Charset($sCharset);
110-
} else if (self::identifierIs($sIdentifier, 'keyframes')) {
110+
} else if ($this->identifierIs($sIdentifier, 'keyframes')) {
111111
$oResult = new KeyFrame();
112112
$oResult->setVendorKeyFrame($sIdentifier);
113113
$oResult->setAnimationName(trim($this->consumeUntil('{', false, true)));
@@ -135,7 +135,7 @@ private function parseAtRule() {
135135
$this->consumeWhiteSpace();
136136
$bUseRuleSet = true;
137137
foreach($this->blockRules as $sBlockRuleName) {
138-
if(self::identifierIs($sIdentifier, $sBlockRuleName)) {
138+
if($this->identifierIs($sIdentifier, $sBlockRuleName)) {
139139
$bUseRuleSet = false;
140140
break;
141141
}
@@ -454,8 +454,9 @@ private function parseURLValue() {
454454
/**
455455
* Tests an identifier for a given value. Since identifiers are all keywords, they can be vendor-prefixed. We need to check for these versions too.
456456
*/
457-
private static function identifierIs($sIdentifier, $sMatch, $bCaseInsensitive = true) {
458-
return preg_match("/^(-\\w+-)?$sMatch$/".($bCaseInsensitive ? 'i' : ''), $sIdentifier) === 1;
457+
private function identifierIs($sIdentifier, $sMatch) {
458+
return (strcasecmp($sIdentifier, $sMatch) === 0)
459+
?: preg_match("/^(-\\w+-)?$sMatch$/i", $sIdentifier) === 1;
459460
}
460461

461462
private function comes($sString, $alpha = false) {

0 commit comments

Comments
 (0)