From c7cd323c6b2a78c7e13ebe73c1ebb87e49df2666 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Fri, 17 Aug 2018 16:21:27 -0700 Subject: [PATCH] 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 --- includes/title/MediaWikiTitleCodec.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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 !== '' ) { -- 2.20.1