r54117 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54116‎ | r54117 | r54118 >
Date:18:58, 31 July 2009
Author:nikerabbit
Status:deferred
Tags:
Comment:
* Bugfix in mangler construction
* messageKeyToGroup was deadslow - no idea why, but now it is fast again
Modified paths:
  • /trunk/extensions/Translate/Stats.php (modified) (history)
  • /trunk/extensions/Translate/TranslateUtils.php (modified) (history)
  • /trunk/extensions/Translate/utils/StringMatcher.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/Stats.php
@@ -448,7 +448,7 @@
449449
450450 if ( $this->filters['group'] ) {
451451 $group = TranslateUtils::messageKeyToGroup( $row->rc_namespace, $key );
452 - if ( $group === null ) return - 1;
 452+ if ( $group === null ) return -1;
453453 $indexKey .= $group;
454454 }
455455
Index: trunk/extensions/Translate/utils/StringMatcher.php
@@ -17,10 +17,10 @@
1818 protected $aRegex = array();
1919
2020 public static function EmptyMatcher() {
21 - return new StringMatcher( '', array() );
 21+ return new StringMatcher;
2222 }
2323
24 - public function __construct( $prefix, $patterns = array() ) {
 24+ public function __construct( $prefix = '', $patterns = array() ) {
2525 $this->sPrefix = $prefix;
2626 $this->init( $patterns );
2727 }
Index: trunk/extensions/Translate/TranslateUtils.php
@@ -167,18 +167,28 @@
168168 return $selector->getHTML();
169169 }
170170
 171+ static $mi = null;
 172+
171173 public static function messageKeyToGroup( $namespace, $key ) {
172 - $normkey = self::normaliseKey( $namespace, $key );
173 - $index = self::messageIndex();
174 - $group = @$index[$normkey];
 174+ if ( self::$mi === null ) self::messageIndex();
 175+
 176+ # Performance hotspot
 177+ #$normkey = self::normaliseKey( $namespace, $key );
 178+ $normkey = str_replace( " ", "_", strtolower( "$namespace:$key" ) );
 179+
 180+ $group = @self::$mi[$normkey];
175181 if ( is_array($group) ) $group = $group[0];
176182 return $group;
177183 }
178184
179185 public static function messageKeyToGroups( $namespace, $key ) {
180 - $normkey = self::normaliseKey( $namespace, $key );
181 - $index = self::messageIndex();
182 - return (array) @$index[$normkey];
 186+ if ( self::$mi === null ) self::messageIndex();
 187+
 188+ # Performance hotspot
 189+ #$normkey = self::normaliseKey( $namespace, $key );
 190+ $normkey = str_replace( " ", "_", strtolower( "$namespace:$key" ) );
 191+
 192+ return (array) @self::$mi[$normkey];
183193 }
184194
185195 public static function normaliseKey( $namespace, $key ) {
@@ -186,9 +196,6 @@
187197 }
188198
189199 public static function messageIndex() {
190 - static $keyToGroup = null;
191 - if ( $keyToGroup !== null ) return $keyToGroup;
192 -
193200 global $wgCacheDirectory;
194201 $filename = "$wgCacheDirectory/translate_messageindex.cdb";
195202 if ( !file_exists($filename) ) MessageIndexRebuilder::execute();
@@ -201,6 +208,7 @@
202209 wfDebug( __METHOD__ . ": Message index missing." );
203210 }
204211
 212+ self::$mi = $keyToGroup;
205213 return $keyToGroup;
206214 }
207215

Status & tagging log