From 7710788d3ac1f0dfed9b304f16820869edd3892e Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 18 Jan 2005 11:52:06 +0000 Subject: [PATCH] * Remove unnecessary initialization and double-caching of parser variables This saves a couple milliseconds; since the variables are internally cached there's no benefit to running every variable when we're often just going to use one or two (Sitename in messages for instance) --- includes/Parser.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/includes/Parser.php b/includes/Parser.php index 375f988013..3898154c23 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -1788,7 +1788,7 @@ class Parser $this->mVariables = array(); foreach ( $wgVariableIDs as $id ) { $mw =& MagicWord::get( $id ); - $mw->addToArray( $this->mVariables, $this->getVariableValue( $id ) ); + $mw->addToArray( $this->mVariables, $id ); } wfProfileOut( $fname ); } @@ -1846,6 +1846,7 @@ class Parser */ function variableSubstitution( $matches ) { $fname = 'parser::variableSubstitution'; + $varname = $matches[1]; wfProfileIn( $fname ); if ( !$this->mVariables ) { $this->initialiseVariables(); @@ -1854,14 +1855,15 @@ class Parser if ( $this->mOutputType == OT_WIKI ) { # Do only magic variables prefixed by SUBST $mwSubst =& MagicWord::get( MAG_SUBST ); - if (!$mwSubst->matchStartAndRemove( $matches[1] )) + if (!$mwSubst->matchStartAndRemove( $varname )) $skip = true; # Note that if we don't substitute the variable below, # we don't remove the {{subst:}} magic word, in case # it is a template rather than a magic variable. } - if ( !$skip && array_key_exists( $matches[1], $this->mVariables ) ) { - $text = $this->mVariables[$matches[1]]; + if ( !$skip && array_key_exists( $varname, $this->mVariables ) ) { + $id = $this->mVariables[$varname]; + $text = $this->getVariableValue( $id ); $this->mOutput->mContainsOldMagic = true; } else { $text = $matches[0]; -- 2.20.1