From cfda5e7efa0c1de64fe4036eb56f8b90c081c87f Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Thu, 7 Mar 2019 10:55:31 +0100 Subject: [PATCH] Streamline code involving .= string concatenations MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This was inspired by Idbbdb31. Originally, I did a regex search for code that did string concatenations like `$str = $str . …` and replaced them all with the .= operator. A duplicate patch was uploaded by another author. I rebeased this patch on top of the other, which leaves all the manual optimizations I did. Change-Id: Iaeb73d9c63302c9409bd1051b91e0d2bd77788a7 --- includes/EditPage.php | 21 +++++++++------------ includes/db/DatabaseOracle.php | 3 ++- includes/filerepo/file/ForeignAPIFile.php | 15 +++++++-------- includes/libs/objectcache/BagOStuff.php | 3 +-- includes/media/DjVuImage.php | 3 ++- languages/Language.php | 6 ++---- 6 files changed, 23 insertions(+), 28 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 2048b87dd5..41238dff60 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -1667,11 +1667,10 @@ class EditPage { case self::AS_SUCCESS_NEW_ARTICLE: $query = $resultDetails['redirect'] ? 'redirect=no' : ''; if ( $extraQueryRedirect ) { - if ( $query === '' ) { - $query = $extraQueryRedirect; - } else { - $query .= '&' . $extraQueryRedirect; + if ( $query !== '' ) { + $query .= '&'; } + $query .= $extraQueryRedirect; } $anchor = $resultDetails['sectionanchor'] ?? ''; $out->redirect( $this->mTitle->getFullURL( $query ) . $anchor ); @@ -1688,18 +1687,16 @@ class EditPage { ); if ( $resultDetails['redirect'] ) { - if ( $extraQuery == '' ) { - $extraQuery = 'redirect=no'; - } else { - $extraQuery = 'redirect=no&' . $extraQuery; + if ( $extraQuery !== '' ) { + $extraQuery = '&' . $extraQuery; } + $extraQuery = 'redirect=no' . $extraQuery; } if ( $extraQueryRedirect ) { - if ( $extraQuery === '' ) { - $extraQuery = $extraQueryRedirect; - } else { - $extraQuery .= '&' . $extraQueryRedirect; + if ( $extraQuery !== '' ) { + $extraQuery .= '&'; } + $extraQuery .= $extraQueryRedirect; } $out->redirect( $this->mTitle->getFullURL( $extraQuery ) . $sectionanchor ); diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index 9cf924ff24..bb2d3f780c 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -565,7 +565,8 @@ class DatabaseOracle extends Database { // count-alias subselect fields to avoid abigious definition errors $i = 0; foreach ( $varMap as &$val ) { - $val .= ' field' . ( $i++ ); + $val .= ' field' . $i; + $i++; } $selectSql = $this->selectSQLText( diff --git a/includes/filerepo/file/ForeignAPIFile.php b/includes/filerepo/file/ForeignAPIFile.php index 8e0242d3cf..c49810cfeb 100644 --- a/includes/filerepo/file/ForeignAPIFile.php +++ b/includes/filerepo/file/ForeignAPIFile.php @@ -318,16 +318,15 @@ class ForeignAPIFile extends File { * @return null|string */ function getThumbPath( $suffix = '' ) { - if ( $this->repo->canCacheThumbs() ) { - $path = $this->repo->getZonePath( 'thumb' ) . '/' . $this->getHashPath(); - if ( $suffix ) { - $path .= $suffix . '/'; - } - - return $path; - } else { + if ( !$this->repo->canCacheThumbs() ) { return null; } + + $path = $this->repo->getZonePath( 'thumb' ) . '/' . $this->getHashPath(); + if ( $suffix ) { + $path .= $suffix . '/'; + } + return $path; } /** diff --git a/includes/libs/objectcache/BagOStuff.php b/includes/libs/objectcache/BagOStuff.php index 44c79f327e..6cad5dfbfb 100644 --- a/includes/libs/objectcache/BagOStuff.php +++ b/includes/libs/objectcache/BagOStuff.php @@ -810,8 +810,7 @@ abstract class BagOStuff implements IExpiringStore, LoggerAwareInterface { public function makeKeyInternal( $keyspace, $args ) { $key = $keyspace; foreach ( $args as $arg ) { - $arg = str_replace( ':', '%3A', $arg ); - $key .= ':' . $arg; + $key .= ':' . str_replace( ':', '%3A', $arg ); } return strtr( $key, ' ', '_' ); } diff --git a/includes/media/DjVuImage.php b/includes/media/DjVuImage.php index 04ddda2e10..d059cd8289 100644 --- a/includes/media/DjVuImage.php +++ b/includes/media/DjVuImage.php @@ -286,7 +286,8 @@ EOR; $txt = preg_replace_callback( $reg, [ $this, 'pageTextCallback' ], $txt ); $txt = "\n\n\n" . $txt . "\n\n"; $xml = preg_replace( "//", "", $xml, 1 ) . - $txt . ''; + $txt . + ''; } } diff --git a/languages/Language.php b/languages/Language.php index 3dbde01b63..bc69dadaf2 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -3593,14 +3593,12 @@ class Language { $length -= $ellipsisLength; $string = $getSubstring( $string, 0, $length ); // xyz... $string = $this->removeBadCharLast( $string ); - $string = rtrim( $string ); - $string = $string . $ellipsis; + $string = rtrim( $string ) . $ellipsis; } else { $length += $ellipsisLength; $string = $getSubstring( $string, $length ); // ...xyz $string = $this->removeBadCharFirst( $string ); - $string = ltrim( $string ); - $string = $ellipsis . $string; + $string = $ellipsis . ltrim( $string ); } } -- 2.20.1