Skip to content

Commit 6077052

Browse files
committed
More efficient sizeUnits determination
1 parent e7ef7a8 commit 6077052

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

lib/Sabberworm/CSS/Parser.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ public function __construct($sText, Settings $oParserSettings = null) {
4343
}
4444
$this->oParserSettings = $oParserSettings;
4545
$this->blockRules = explode('/', AtRule::BLOCK_RULES);
46-
$this->sizeUnits = explode('/', Size::ABSOLUTE_SIZE_UNITS.'/'.Size::RELATIVE_SIZE_UNITS.'/'.Size::NON_SIZE_UNITS);
46+
47+
foreach (explode('/', Size::ABSOLUTE_SIZE_UNITS.'/'.Size::RELATIVE_SIZE_UNITS.'/'.Size::NON_SIZE_UNITS) as $val) {
48+
$size = strlen($val);
49+
if (isset($this->sizeUnits[$size])) {
50+
$this->sizeUnits[$size][] = $val;
51+
} else {
52+
$this->sizeUnits[$size] = array($val);
53+
}
54+
}
55+
ksort($this->sizeUnits, SORT_NUMERIC);
4756
}
4857

4958
public function setCharset($sCharset) {
@@ -397,11 +406,12 @@ private function parseNumericValue($bForColor = false) {
397406
$sSize .= $this->consume(1);
398407
}
399408
}
409+
400410
$sUnit = null;
401-
foreach($this->sizeUnits as $sDefinedUnit) {
402-
if ($this->comes($sDefinedUnit, true)) {
403-
$sUnit = $sDefinedUnit;
404-
$this->consume($sDefinedUnit);
411+
foreach ($this->sizeUnits as $len => $val) {
412+
if (($pos = array_search($this->peek($len), $val)) !== false) {
413+
$sUnit = $val[$pos];
414+
$this->consume($len);
405415
break;
406416
}
407417
}

0 commit comments

Comments
 (0)