From: Thiemo Kreuz Date: Wed, 27 Mar 2019 10:25:25 +0000 (+0100) Subject: title: Rewrite Title::getBaseText() for performance/readability X-Git-Tag: 1.34.0-rc.0~2287^2 X-Git-Url: http://git.cyclocoop.org//%27http:/code.google.com/p/ie7-js//%27?a=commitdiff_plain;h=7de043dc87c2822508cf6ffd9a176872b231b4d2;p=lhc%2Fweb%2Fwiklou.git title: Rewrite Title::getBaseText() for performance/readability This code does not really need to explode a path in all it's individual segments. All it needs to know is *if* a title is a path (with at least one slash), and then remove the last segment. That's pretty much exactly what the code proposed in this patch now does. Change-Id: I9cf714f7bb637ecd9e1f44340219c76ddd60ee29 --- diff --git a/includes/Title.php b/includes/Title.php index 0f45839577..ce0b9595c5 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1702,16 +1702,18 @@ class Title implements LinkTarget, IDBAccessObject { * @return string Base name */ public function getBaseText() { + $text = $this->getText(); if ( !MWNamespace::hasSubpages( $this->mNamespace ) ) { - return $this->getText(); + return $text; } - $parts = explode( '/', $this->getText() ); - # Don't discard the real title if there's no subpage involved - if ( count( $parts ) > 1 ) { - unset( $parts[count( $parts ) - 1] ); + $lastSlashPos = strrpos( $text, '/' ); + // Don't discard the real title if there's no subpage involved + if ( $lastSlashPos === false ) { + return $text; } - return implode( '/', $parts ); + + return substr( $text, 0, $lastSlashPos ); } /**