From 6bfbb32418a5ae69156ab23d9fb35ab6f77a843e Mon Sep 17 00:00:00 2001 From: robocoder <anthon.pang@gmail.com> Date: Fri, 27 Nov 2009 20:57:13 +0000 Subject: [PATCH] fixes #1049 - peephole optimizations (assignment to a temporary variable before returning) git-svn-id: http://dev.piwik.org/svn/trunk@1613 59fd770c-687e-43c8-a1e3-f5a4ff64c105 --- core/DataTable.php | 17 +++++------------ core/Log.php | 8 +++----- core/Period.php | 3 +-- core/PluginsManager.php | 4 +--- core/TablePartitioning.php | 12 ++---------- 5 files changed, 12 insertions(+), 32 deletions(-) diff --git a/core/DataTable.php b/core/DataTable.php index a5590e1cbb..13f7f1e3ff 100644 --- a/core/DataTable.php +++ b/core/DataTable.php @@ -588,14 +588,13 @@ class Piwik_DataTable */ public function getRowsCount() { - $count = count($this->rows); if(is_null($this->summaryRow)) { - return $count; + return count($this->rows); } else { - return $count + 1; + return count($this->rows) + 1; } } @@ -820,10 +819,7 @@ class Piwik_DataTable $table1->rebuildIndex(); $table2->rebuildIndex(); - $countrows1 = $table1->getRowsCount(); - $countrows2 = $table2->getRowsCount(); - - if($countrows1 != $countrows2) + if($table1->getRowsCount() != $table2->getRowsCount()) { return false; } @@ -831,11 +827,8 @@ class Piwik_DataTable foreach($rows1 as $row1) { $row2 = $table2->getRowFromLabel($row1->getColumn('label')); - if($row2 === false) - { - return false; - } - if( !Piwik_DataTable_Row::isEqual($row1,$row2) ) + if($row2 === false + || !Piwik_DataTable_Row::isEqual($row1,$row2)) { return false; } diff --git a/core/Log.php b/core/Log.php index 0be03c98d0..ca477bec44 100644 --- a/core/Log.php +++ b/core/Log.php @@ -139,8 +139,7 @@ class Piwik_Log_Formatter_FileFormatter implements Zend_Log_Formatter_Interface } $ts = $event['timestamp']; unset($event['timestamp']); - $str = $ts . ' ' . implode(" ", $event) . "\n"; - return $str; + return $ts . ' ' . implode(" ", $event) . "\n"; } } @@ -156,11 +155,10 @@ class Piwik_Log_Formatter_ScreenFormatter implements Zend_Log_Formatter_Interfac // no injection in error messages, backtrace when displayed on screen return array_map('htmlspecialchars', $event); } - + function format($string) { - $string = self::getFormattedString($string); - return $string; + return self::getFormattedString($string); } static public function getFormattedString($string) diff --git a/core/Period.php b/core/Period.php index 7fd59b84e8..a8c880f32f 100644 --- a/core/Period.php +++ b/core/Period.php @@ -221,8 +221,7 @@ abstract class Piwik_Period public function __toString() { - $elements = $this->toString(); - return implode(",", $elements); + return implode(",", $this->toString()); } public function get( $part= null ) diff --git a/core/PluginsManager.php b/core/PluginsManager.php index 5e2c3e20d7..3c64ef012f 100644 --- a/core/PluginsManager.php +++ b/core/PluginsManager.php @@ -192,9 +192,7 @@ class Piwik_PluginsManager */ public function getLoadedPluginsName() { - $oPlugins = $this->getLoadedPlugins(); - $pluginNames = array_map('get_class',$oPlugins); - return $pluginNames; + return array_map('get_class', $this->getLoadedPlugins()); } /** diff --git a/core/TablePartitioning.php b/core/TablePartitioning.php index 1edcbb4ef4..d74eefff3b 100644 --- a/core/TablePartitioning.php +++ b/core/TablePartitioning.php @@ -108,11 +108,7 @@ class Piwik_TablePartitioning_Monthly extends Piwik_TablePartitioning protected function generateTableName() { $config = Zend_Registry::get('config'); - $prefixTables = $config->database->tables_prefix; - - $date = date("Y_m", $this->timestamp); - - return $prefixTables . $this->tableName . "_" . $date; + return $config->database->tables_prefix . $this->tableName . "_" . date("Y_m", $this->timestamp); } } @@ -131,10 +127,6 @@ class Piwik_TablePartitioning_Daily extends Piwik_TablePartitioning protected function generateTableName() { $config = Zend_Registry::get('config'); - $prefixTables = $config->database->tables_prefix; - - $date = date("Y_m_d", $this->timestamp); - - return $prefixTables . $this->tableName . "_" . $date; + return $config->database->tables_prefix . $this->tableName . "_" . date("Y_m_d", $this->timestamp); } } -- GitLab