From: Antoine Musso Date: Wed, 29 May 2013 10:21:42 +0000 (+0200) Subject: Micro optimization when fetching a magic from cache X-Git-Tag: 1.31.0-rc.0~19537^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/comptes/ajouter.php?a=commitdiff_plain;h=780ec298da17e2ec052bc40541bad822b62498f4;p=lhc%2Fweb%2Fwiklou.git Micro optimization when fetching a magic from cache The Language::getMagic() methods would request a full copy of the magic words array from the cache. Instead use LocalisationCache::getSubitem() to only fetch the magic word we are interested in. I do not think that makes that much of a difference, but that is certainly nicer. Note that getSubItem() returns null on miss instead of the previous 'false', that still works for the !is_array(). Change-Id: I02824fd313eeecb5e5b26cb79d7b5549f6648f91 --- diff --git a/languages/Language.php b/languages/Language.php index ea34363b4f..92ea75c814 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -2953,12 +2953,16 @@ class Language { } /** + * Get all magic words from cache. * @return array */ function getMagicWords() { return self::$dataCache->getItem( $this->mCode, 'magicWords' ); } + /** + * Run the LanguageGetMagic hook once. + */ protected function doMagicHook() { if ( $this->mMagicHookDone ) { return; @@ -2975,17 +2979,16 @@ class Language { * @param $mw */ function getMagic( $mw ) { - $this->doMagicHook(); + // Saves a function call + if ( ! $this->mMagicHookDone ) { + $this->doMagicHook(); + } if ( isset( $this->mMagicExtensions[$mw->mId] ) ) { $rawEntry = $this->mMagicExtensions[$mw->mId]; } else { - $magicWords = $this->getMagicWords(); - if ( isset( $magicWords[$mw->mId] ) ) { - $rawEntry = $magicWords[$mw->mId]; - } else { - $rawEntry = false; - } + $rawEntry = self::$dataCache->getSubitem( + $this->mCode, 'magicWords', $mw->mId ); } if ( !is_array( $rawEntry ) ) {