r55496 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55495‎ | r55496 | r55497 >
Date:19:55, 22 August 2009
Author:brion
Status:ok
Tags:
Comment:
Reduce output size of Skin::makeVariablesScript() for the head variables.
Drops a lot of unnecessary whitespace (but keeps newlines for legibility) and puts multiple defs into a single 'var' statement.
Reduces the head vars script from 1485 bytes to 1201 (nearly 20% savings), though this is of course reduced with gzipping (27 bytes, 4%). Cutting those bytes out of *every dang request* doesn't hurt though. :)
Modified paths:
  • /trunk/phase3/includes/Skin.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Skin.php
@@ -333,13 +333,17 @@
334334 }
335335
336336 static function makeVariablesScript( $data ) {
337 - $r = array();
338 - foreach ( $data as $name => $value ) {
339 - $encValue = Xml::encodeJsVar( $value );
340 - $r[] = "var $name = $encValue;";
 337+ if( $data ) {
 338+ $r = array();
 339+ foreach ( $data as $name => $value ) {
 340+ $encValue = Xml::encodeJsVar( $value );
 341+ $r[] = "$name=$encValue";
 342+ }
 343+ $js = 'var ' . implode( ",\n", $r ) . ';';
 344+ return Html::inlineScript( "\n$js\n" );
 345+ } else {
 346+ return '';
341347 }
342 - return Html::inlineScript( "\n\t\t" . implode( "\n\t\t", $r ) .
343 - "\n\t\t" );
344348 }
345349
346350 /**

Status & tagging log