Skip to content

Make Minify_CSS_Compressor class static #713

Description

@sedimentation-fault

I fail to see how any method of the Minify_CSS_Compressor class in minify/lib/Minify/CSS/Compressor.php is dependent on the class instance (i.e. on $this). The only place where $this is used is in the callbacks to preg_match_callback:

$css = preg_replace_callback($pattern, array($this, '_selectorsCB'), $css);

but this can be changed to

$css = preg_replace_callback($pattern, array(get_called_class(), '_selectorsCB'), $css);

Just remember to initialize the one and only true property _inHack(_options is not used anyway) like this

		// Initialize!
		self::$_inHack = false;

in function _process(). Then you can declare all methods static and refer to $_inHack with self::$_inHack. There is nothing more to it - simple. 😉

WHY

You spare an instantiation of Minify_CSS_Compressor each time a script minifies a CSS. In high-traffic scenarios, this might make a measurable difference.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions