* Remove unnecessary initialization and double-caching of parser variables
authorBrion Vibber <brion@users.mediawiki.org>
Tue, 18 Jan 2005 11:52:06 +0000 (11:52 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Tue, 18 Jan 2005 11:52:06 +0000 (11:52 +0000)
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

index 375f988..3898154 100644 (file)
@@ -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];