Permalink
Browse files

Update min/lib/CSSmin.php

Precount loops for increased performance.
  • Loading branch information...
acidvertigo committed Nov 7, 2012
1 parent 248aff9 commit 7262b89d021d1a84caf8632605d045a6800eff5c
Showing with 12 additions and 6 deletions.
  1. +12 −6 min/lib/CSSmin.php
View
@@ -133,7 +133,8 @@ public function run($css = '', $linebreak_pos = FALSE)
}
// Minify each chunk
- for ($i = 0, $n = count($css_chunks); $i < $n; $i++) {
+ $n = count($css_chunks);
+ for ($i = 0; $i < $n; $i++) {
$css_chunks[$i] = $this->minify($css_chunks[$i], $linebreak_pos);
// Keep the first @charset at-rule found
if (empty($charset) && preg_match($charset_regexp, $css_chunks[$i], $matches)) {
@@ -216,7 +217,8 @@ private function do_raise_php_limits()
private function minify($css, $linebreak_pos)
{
// strings are safe, now wrestle the comments
- for ($i = 0, $max = count($this->comments); $i < $max; $i++) {
+ $max = count($this->comments);
+ for ($i = 0; $i < $max; $i++) {
$token = $this->comments[$i];
$placeholder = '/' . self::COMMENT . $i . '___/';
@@ -368,7 +370,8 @@ private function minify($css, $linebreak_pos)
$css = preg_replace('/'. self::NL .'/', "\n", $css);
// restore preserved comments and strings
- for ($i = 0, $max = count($this->preserved_tokens); $i < $max; $i++) {
+ $max = count($this->preserved_tokens);
+ for ($i = 0; $i < $max; $i++) {
$css = preg_replace('/' . self::TOKEN . $i . '___/', $this->preserved_tokens[$i], $css, 1);
}
@@ -527,7 +530,8 @@ private function replace_string($matches)
// maybe the string contains a comment-like substring?
// one, maybe more? put'em back then
if (($pos = $this->index_of($match, self::COMMENT)) >= 0) {
- for ($i = 0, $max = count($this->comments); $i < $max; $i++) {
+ $max = count($this->comments);
+ for ($i = 0; $i < $max; $i++) {
$match = preg_replace('/' . self::COMMENT . $i . '___/', $this->comments[$i], $match, 1);
}
}
@@ -555,15 +559,17 @@ private function rgb_to_hex($matches)
// Support for percentage values rgb(100%, 0%, 45%);
if ($this->index_of($matches[1], '%') >= 0){
$rgbcolors = explode(',', str_replace('%', '', $matches[1]));
- for ($i = 0; $i < count($rgbcolors); $i++) {
+ $rgb = count($rgbcolors);
+ for ($i = 0; $i < $rgb; $i++) {
$rgbcolors[$i] = $this->round_number(floatval($rgbcolors[$i]) * 2.55);
}
} else {
$rgbcolors = explode(',', $matches[1]);
}
// Values outside the sRGB color space should be clipped (0-255)
- for ($i = 0; $i < count($rgbcolors); $i++) {
+ $rgb = count($rgbcolors);
+ for ($i = 0; $i $rgb; $i++) {
@acidvertigo

acidvertigo Nov 7, 2012

Owner

Error typo should be $i < $rgb

$rgbcolors[$i] = $this->clamp_number(intval($rgbcolors[$i], 10), 0, 255);
$rgbcolors[$i] = sprintf("%02x", $rgbcolors[$i]);
}

0 comments on commit 7262b89

Please sign in to comment.