From c4afeb3fe6965439047b5a9fb35699fabdb1a507 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Tue, 19 Jan 2010 09:41:17 -0200 Subject: [PATCH] Minor optimization on datasource and Mysql[i]. --- cake/libs/model/datasources/datasource.php | 10 +++++----- cake/libs/model/datasources/dbo/dbo_mysql.php | 3 +-- cake/libs/model/datasources/dbo/dbo_mysqli.php | 8 +++----- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/cake/libs/model/datasources/datasource.php b/cake/libs/model/datasources/datasource.php index 99d3e8568..510b615e9 100644 --- a/cake/libs/model/datasources/datasource.php +++ b/cake/libs/model/datasources/datasource.php @@ -436,11 +436,11 @@ class DataSource extends Object { * @access public */ function isInterfaceSupported($interface) { - $methods = get_class_methods(get_class($this)); - $methods = strtolower(implode('|', $methods)); - $methods = explode('|', $methods); - $return = in_array(strtolower($interface), $methods); - return $return; + static $methods = false; + if ($methods === false) { + $methods = array_map('strtolower', get_class_methods($this)); + } + return in_array(strtolower($interface), $methods); } /** diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 2d512da80..2fd07d961 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -605,7 +605,7 @@ class DboMysql extends DboMysqlBase { } else { $tables = array(); - while ($line = mysql_fetch_array($result)) { + while ($line = mysql_fetch_row($result)) { $tables[] = $line[0]; } parent::listSources($tables); @@ -727,7 +727,6 @@ class DboMysql extends DboMysqlBase { $j = 0; while ($j < $numFields) { - $column = mysql_fetch_field($results,$j); if (!empty($column->table)) { $this->map[$index++] = array($column->table, $column->name); diff --git a/cake/libs/model/datasources/dbo/dbo_mysqli.php b/cake/libs/model/datasources/dbo/dbo_mysqli.php index 1f4719176..d4d5ada38 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysqli.php +++ b/cake/libs/model/datasources/dbo/dbo_mysqli.php @@ -140,7 +140,7 @@ class DboMysqli extends DboMysqlBase { */ function listSources() { $cache = parent::listSources(); - if ($cache != null) { + if ($cache !== null) { return $cache; } $result = $this->_execute('SHOW TABLES FROM ' . $this->name($this->config['database']) . ';'); @@ -151,7 +151,7 @@ class DboMysqli extends DboMysqlBase { $tables = array(); - while ($line = mysqli_fetch_array($result)) { + while ($line = mysqli_fetch_row($result)) { $tables[] = $line[0]; } parent::listSources($tables); @@ -290,14 +290,12 @@ class DboMysqli extends DboMysqlBase { function fetchResult() { if ($row = mysqli_fetch_row($this->results)) { $resultRow = array(); - $i = 0; foreach ($row as $index => $field) { $table = $column = null; - if (count($this->map[$index]) == 2) { + if (count($this->map[$index]) === 2) { list($table, $column) = $this->map[$index]; } $resultRow[$table][$column] = $row[$index]; - $i++; } return $resultRow; }