From d66f60ed4309a7d9c1b815290ca99fd2a3082a53 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sun, 28 Nov 2004 03:29:50 +0000 Subject: [PATCH] Loop invariant optimization: skip further checks for subpages on namespaces where subpages aren't allowed. Saves ~20ms on [[List of Royal Navy ship names]] on my test rig. --- includes/Parser.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/includes/Parser.php b/includes/Parser.php index 9174af33c3..8bd820be73 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -700,7 +700,7 @@ class Parser $text = $wgDateFormatter->reformat( $this->mOptions->getDateFormat(), $text ); } $text = $this->doAllQuotes( $text ); - $text = $this->replaceInternalLinks ( $text ); + $text = $this->replaceInternalLinks( $text ); $text = $this->replaceExternalLinks( $text ); # replaceInternalLinks may sometimes leave behind @@ -1176,6 +1176,8 @@ class Parser wfProfileOut( $fname.'-setup' ); $checkVariantLink = sizeof($wgContLang->getVariants())>1; + $useSubpages = $this->areSubpagesAllowed(); + # Loop for each link for ($k = 0; isset( $a[$k] ); $k++) { $line = $a[$k]; @@ -1221,7 +1223,11 @@ class Parser } # Make subpage if necessary - $link = $this->maybeDoSubpageLink( $m[1], $text ); + if( $useSubpages ) { + $link = $this->maybeDoSubpageLink( $m[1], $text ); + } else { + $link = $m[1]; + } $noforce = (substr($m[1], 0, 1) != ':'); if (!$noforce) { @@ -1365,6 +1371,16 @@ class Parser return $s; } + /** + * Return true if subpage links should be expanded on this page. + * @return bool + */ + function areSubpagesAllowed() { + # Some namespaces don't allow subpages + global $wgNamespacesWithSubpages; + return !empty($wgNamespacesWithSubpages[$this->mTitle->getNamespace()]); + } + /** * Handle link to subpage if necessary * @param string $target the source of the link @@ -1378,7 +1394,6 @@ class Parser # :Foobar -- override special treatment of prefix (images, language links) # /Foobar -- convert to CurrentPage/Foobar # /Foobar/ -- convert to CurrentPage/Foobar, strip the initial / from text - global $wgNamespacesWithSubpages; $fname = 'Parser::maybeDoSubpageLink'; wfProfileIn( $fname ); @@ -1393,7 +1408,7 @@ class Parser } # Some namespaces don't allow subpages - if(!empty($wgNamespacesWithSubpages[$this->mTitle->getNamespace()])) { + if( $this->areSubpagesAllowed() ) { # subpages allowed here $ret = $this->mTitle->getPrefixedText(). '/' . trim($noslash); if( '' === $text ) { -- 2.20.1