...by instance caching the result on the LinkTarget object.
Title::getPrefixedText() is an extremely hot function that has been
fully optimized over the years due to its usage basically everywhere in
MediaWiki.
Apply the same treatment to TitleFormatter, but keep the caching as part
of the LinkTarget instance so we can share caches across Title and
TitleFormatter. Once Title is switched over to using TitleFormatter
internally, we can probably centralize the cache again, and get rid of
the public but marked @private member variables.
Bug: T201801
Change-Id: I4ae2d6b176f69f66720473aeae85e39a601a9781
/** @var bool Boolean for initialisation on demand */
public $mRestrictionsLoaded = false;
/** @var bool Boolean for initialisation on demand */
public $mRestrictionsLoaded = false;
- /** @var string Text form including namespace/interwiki, initialised on demand */
- protected $mPrefixedText = null;
+ /**
+ * Text form including namespace/interwiki, initialised on demand
+ *
+ * Only public to share cache with TitleFormatter
+ *
+ * @private
+ * @var string
+ */
+ public $prefixedText = null;
/** @var mixed Cached value for getTitleProtection (create protection) */
public $mTitleProtection;
/** @var mixed Cached value for getTitleProtection (create protection) */
public $mTitleProtection;
* @return string The prefixed title, with spaces
*/
public function getPrefixedText() {
* @return string The prefixed title, with spaces
*/
public function getPrefixedText() {
- if ( $this->mPrefixedText === null ) {
+ if ( $this->prefixedText === null ) {
$s = $this->prefix( $this->mTextform );
$s = strtr( $s, '_', ' ' );
$s = $this->prefix( $this->mTextform );
$s = strtr( $s, '_', ' ' );
- $this->mPrefixedText = $s;
+ $this->prefixedText = $s;
- return $this->mPrefixedText;
+ return $this->prefixedText;
* @return string
*/
public function getPrefixedText( LinkTarget $title ) {
* @return string
*/
public function getPrefixedText( LinkTarget $title ) {
- return $this->formatTitle(
- $title->getNamespace(),
- $title->getText(),
- '',
- $title->getInterwiki()
- );
+ if ( !isset( $title->prefixedText ) ) {
+ $title->prefixedText = $this->formatTitle(
+ $title->getNamespace(),
+ $title->getText(),
+ '',
+ $title->getInterwiki()
+ );
+ }
+
+ return $title->prefixedText;
+ /**
+ * Text form including namespace/interwiki, initialised on demand
+ *
+ * Only public to share cache with TitleFormatter
+ *
+ * @private
+ * @var string
+ */
+ public $prefixedText = null;
+
/**
* Constructs a TitleValue.
*
/**
* Constructs a TitleValue.
*