r73078 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73077‎ | r73078 | r73079 >
Date:18:33, 15 September 2010
Author:tparscal
Status:ok
Tags:
Comment:
Changed to always calling ResourceLoader::intitialize rather than checking the state of ResourceLoader::$initialized - allthough this is slower (extra function call overhead) it centralizes the logic. Premature optimization is evil.
Modified paths:
  • /trunk/phase3/includes/ResourceLoader.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ResourceLoader.php
@@ -39,15 +39,13 @@
4040 protected static function initialize() {
4141 global $IP;
4242
43 - // Safety check - this should never be called more than once anyways
44 - if ( self::$initialized ) {
45 - wfDebug( 'ResourceLoader::intitialize was called more than once' );
46 - return;
 43+ // Safety check - this should never be called more than once
 44+ if ( !self::$initialized ) {
 45+ // This needs to be first, because hooks might call ResourceLoader public interfaces which will call this
 46+ self::$initialized = true;
 47+ self::register( include( "$IP/resources/Resources.php" ) );
 48+ wfRunHooks( 'ResourceLoaderRegisterModules' );
4749 }
48 -
49 - self::$initialized = true;
50 - self::register( include( "$IP/resources/Resources.php" ) );
51 - wfRunHooks( 'ResourceLoaderRegisterModules' );
5250 }
5351
5452 /**
@@ -117,9 +115,7 @@
118116 */
119117 public static function register( $name, ResourceLoaderModule $object = null ) {
120118
121 - if ( !self::$initialized ) {
122 - self::initialize();
123 - }
 119+ self::initialize();
124120
125121 // Allow multiple modules to be registered in one call
126122 if ( is_array( $name ) && !isset( $object ) ) {
@@ -147,9 +143,7 @@
148144 */
149145 public static function getModules() {
150146
151 - if ( !self::$initialized ) {
152 - self::initialize();
153 - }
 147+ self::initialize();
154148
155149 return self::$modules;
156150 }
@@ -162,9 +156,7 @@
163157 */
164158 public static function getModule( $name ) {
165159
166 - if ( !self::$initialized ) {
167 - self::initialize();
168 - }
 160+ self::initialize();
169161
170162 return isset( self::$modules[$name] ) ? self::$modules[$name] : null;
171163 }
@@ -177,9 +169,7 @@
178170 */
179171 public static function getModuleRegistrations( ResourceLoaderContext $context ) {
180172
181 - if ( !self::$initialized ) {
182 - self::initialize();
183 - }
 173+ self::initialize();
184174
185175 $scripts = '';
186176 $registrations = array();
@@ -215,9 +205,7 @@
216206 */
217207 public static function getHighestModifiedTime( ResourceLoaderContext $context ) {
218208
219 - if ( !self::$initialized ) {
220 - self::initialize();
221 - }
 209+ self::initialize();
222210
223211 $time = 1; // wfTimestamp() treats 0 as 'now', so that's not a suitable choice
224212
@@ -237,9 +225,7 @@
238226 global $wgResourceLoaderVersionedClientMaxage, $wgResourceLoaderVersionedServerMaxage;
239227 global $wgResourceLoaderUnversionedServerMaxage, $wgResourceLoaderUnversionedClientMaxage;
240228
241 - if ( !self::$initialized ) {
242 - self::initialize();
243 - }
 229+ self::initialize();
244230
245231 // Split requested modules into two groups, modules and missing
246232 $modules = array();

Status & tagging log