Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Minify_CSS_Compressor class static #713

Open
sedimentation-fault opened this issue Jun 16, 2024 · 0 comments
Open

Make Minify_CSS_Compressor class static #713

sedimentation-fault opened this issue Jun 16, 2024 · 0 comments

Comments

@sedimentation-fault
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant