TitleFormatter: Don't look up namespace name for ns 0
authorKunal Mehta <legoktm@member.fsf.org>
Fri, 17 Aug 2018 23:21:27 +0000 (16:21 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Sat, 18 Aug 2018 00:10:46 +0000 (17:10 -0700)
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

includes/title/MediaWikiTitleCodec.php

index a00ef1e..daa4dd5 100644 (file)
@@ -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 !== '' ) {