From: Kunal Mehta Date: Fri, 17 Aug 2018 23:21:27 +0000 (-0700) Subject: TitleFormatter: Don't look up namespace name for ns 0 X-Git-Tag: 1.34.0-rc.0~4341^2~2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/modifier.php?a=commitdiff_plain;h=c7cd323c6b2a78c7e13ebe73c1ebb87e49df2666;p=lhc%2Fweb%2Fwiklou.git TitleFormatter: Don't look up namespace name for ns 0 It's hardcoded to empty string, so we can skip some code. Profiling (after switching the benchmark script to use NS_MAIN) showed no noticable improvements in getPrefixedText(). Change-Id: Id6b044a51648d0a3f58331ac0427f9d5cd9d8f0f --- diff --git a/includes/title/MediaWikiTitleCodec.php b/includes/title/MediaWikiTitleCodec.php index a00ef1e966..daa4dd55b5 100644 --- a/includes/title/MediaWikiTitleCodec.php +++ b/includes/title/MediaWikiTitleCodec.php @@ -112,18 +112,16 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser { * @return string */ public function formatTitle( $namespace, $text, $fragment = '', $interwiki = '' ) { - if ( $namespace !== false ) { + if ( $namespace !== 0 && $namespace !== false ) { // Try to get a namespace name, but fallback - // to empty string if it doesn't exist + // to empty string if it doesn't exist. And + // assume that ns 0 is the empty string. try { $nsName = $this->getNamespaceName( $namespace, $text ); } catch ( InvalidArgumentException $e ) { $nsName = ''; } - - if ( $namespace !== 0 ) { - $text = $nsName . ':' . $text; - } + $text = $nsName . ':' . $text; } if ( $fragment !== '' ) {