Martineznovo has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/359654 )
Change subject: Performance: Shortcut Language::truncate if there's no need to
truncate
......................................................................
Performance: Shortcut Language::truncate if there's no need to truncate
Return the unmodified string if there's no need to truncate it without
doing a not-so-trivial round of getting a message from the message
cache.
Change-Id: I11ac88672aeb9d1c4f5709b79ad2d17223bd64d8
---
M languages/Language.php
1 file changed, 4 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/54/359654/1
diff --git a/languages/Language.php b/languages/Language.php
index b5eef8c..449bd01 100644
--- a/languages/Language.php
+++ b/languages/Language.php
@@ -3470,15 +3470,16 @@
* @return string
*/
function truncate( $string, $length, $ellipsis = '...', $adjustLength =
true ) {
+ # Check if there is no need to truncate
+ if ( strlen( $string ) <= abs( $length ) ) {
+ return $string; // no need to truncate
+ }
# Use the localized ellipsis character
if ( $ellipsis == '...' ) {
$ellipsis = wfMessage( 'ellipsis' )->inLanguage( $this
)->escaped();
}
- # Check if there is no need to truncate
if ( $length == 0 ) {
return $ellipsis; // convention
- } elseif ( strlen( $string ) <= abs( $length ) ) {
- return $string; // no need to truncate
}
$stringOriginal = $string;
# If ellipsis length is >= $length then we can't apply
$adjustLength
--
To view, visit https://gerrit.wikimedia.org/r/359654
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I11ac88672aeb9d1c4f5709b79ad2d17223bd64d8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Martineznovo <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits