Skip to content

Commit

Permalink
Merge pull request #1426 from samsonasik/count-performance-baseresult
Browse files Browse the repository at this point in the history
performance improvement in Database\BaseResult to use truthy check instead of count($var) when possible
  • Loading branch information
jim-parry authored Nov 8, 2018
2 parents 86587e6 + 60f23b7 commit e432a12
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions system/Database/BaseResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 3.0.0
* @package CodeIgniter
* @author CodeIgniter Dev Team
* @copyright 2014-2018 British Columbia Institute of Technology (https://bcit.ca/)
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 3.0.0
* @filesource
*/

Expand All @@ -45,56 +45,56 @@ abstract class BaseResult implements ResultInterface
/**
* Connection ID
*
* @var resource|object
* @var resource|object
*/
public $connID;

/**
* Result ID
*
* @var resource|object
* @var resource|object
*/
public $resultID;

/**
* Result Array
*
* @var array[]
* @var array[]
*/
public $resultArray = [];

/**
* Result Object
*
* @var object[]
* @var object[]
*/
public $resultObject = [];

/**
* Custom Result Object
*
* @var object[]
* @var object[]
*/
public $customResultObject = [];

/**
* Current Row index
*
* @var int
* @var integer
*/
public $currentRow = 0;

/**
* Number of rows
*
* @var int
* @var integer
*/
public $numRows;

/**
* Row data
*
* @var array
* @var array
*/
public $rowData;

Expand All @@ -108,7 +108,7 @@ abstract class BaseResult implements ResultInterface
*/
public function __construct(&$connID, &$resultID)
{
$this->connID = $connID;
$this->connID = $connID;
$this->resultID = $resultID;
}

Expand Down Expand Up @@ -152,7 +152,7 @@ public function getCustomResultObject(string $className)
{
return $this->customResultObject[$className];
}
elseif ( ! $this->resultID || $this->numRows === 0)
elseif (! $this->resultID || $this->numRows === 0)
{
return [];
}
Expand All @@ -170,7 +170,7 @@ public function getCustomResultObject(string $className)

if ($_data !== null)
{
for ($i = 0; $i < $c; $i ++ )
for ($i = 0; $i < $c; $i ++)
{
$this->customResultObject[$className][$i] = new $className();

Expand Down Expand Up @@ -213,16 +213,16 @@ public function getResultArray(): array
// In the event that query caching is on, the result_id variable
// will not be a valid resource so we'll simply return an empty
// array.
if ( ! $this->resultID || $this->numRows === 0)
if (! $this->resultID || $this->numRows === 0)
{
return [];
}

if (($c = count($this->resultObject)) > 0)
if ($this->resultObject)
{
for ($i = 0; $i < $c; $i ++ )
foreach ($this->resultObject as $row)
{
$this->resultArray[$i] = (array) $this->resultObject[$i];
$this->resultArray[] = (array) $row;
}

return $this->resultArray;
Expand Down Expand Up @@ -256,16 +256,16 @@ public function getResultObject(): array
// In the event that query caching is on, the result_id variable
// will not be a valid resource so we'll simply return an empty
// array.
if ( ! $this->resultID || $this->numRows === 0)
if (! $this->resultID || $this->numRows === 0)
{
return [];
}

if (($c = count($this->resultArray)) > 0)
if ($this->resultArray)
{
for ($i = 0; $i < $c; $i ++ )
foreach ($this->resultArray as $row)
{
$this->resultObject[$i] = (object) $this->resultArray[$i];
$this->resultObject[] = (object) $row;
}

return $this->resultObject;
Expand All @@ -288,14 +288,14 @@ public function getResultObject(): array
*
* If row doesn't exist, returns null.
*
* @param int $n The index of the results to return
* @param string $type The type of result object. 'array', 'object' or class name.
* @param integer $n The index of the results to return
* @param string $type The type of result object. 'array', 'object' or class name.
*
* @return mixed
*/
public function getRow($n = 0, $type = 'object')
{
if ( ! is_numeric($n))
if (! is_numeric($n))
{
// We cache the row data for subsequent uses
is_array($this->rowData) || $this->row_data = $this->getRowArray(0);
Expand Down Expand Up @@ -328,8 +328,8 @@ public function getRow($n = 0, $type = 'object')
*
* If row doesn't exists, returns null.
*
* @param int $n
* @param string $className
* @param integer $n
* @param string $className
*
* @return mixed
*/
Expand Down Expand Up @@ -357,7 +357,7 @@ public function getCustomRowObject($n, string $className)
*
* If row doesn't exist, returns null.
*
* @param int $n
* @param integer $n
*
* @return mixed
*/
Expand All @@ -384,7 +384,7 @@ public function getRowArray($n = 0)
*
* If row doesn't exist, returns null.
*
* @param int $n
* @param integer $n
*
* @return mixed
*/
Expand All @@ -409,15 +409,15 @@ public function getRowObject($n = 0)
/**
* Assigns an item into a particular column slot.
*
* @param $key
* @param $key
* @param null $value
*
* @return mixed
*/
public function setRow($key, $value = null)
{
// We cache the row data for subsequent uses
if ( ! is_array($this->rowData))
if (! is_array($this->rowData))
{
$this->row_data = $this->getRowArray(0);
}
Expand Down Expand Up @@ -543,7 +543,7 @@ public function getUnbufferedRow($type = 'object')
/**
* Gets the number of fields in the result set.
*
* @return int
* @return integer
*/
abstract public function getFieldCount(): int;

Expand Down Expand Up @@ -581,7 +581,7 @@ abstract public function freeResult();
* internally before fetching results to make sure the result set
* starts at zero.
*
* @param int $n
* @param integer $n
*
* @return mixed
*/
Expand Down

0 comments on commit e432a12

Please sign in to comment.