Skip to content

Commit

Permalink
MDL-81327 core: Remove unnecessary table filter
Browse files Browse the repository at this point in the history
The \Traversable interface does not define the `valid` method.
Furthermore, the `valid` method actually checks that there is a _next_
value, which requires the value already be fetched and waiting. This is
not the case for all Iterators. For example the CallbackFilterIterator
does not load the initial value until it is requested.

It is completely unnecessary to do this check anyway as an invalid
Iterator will just not return any values.
  • Loading branch information
andrewnicols authored and laurentdavid committed Apr 9, 2024
1 parent cf01fd6 commit ff4d5f3
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/tablelib.php
Expand Up @@ -2067,6 +2067,8 @@ function __construct($uniqueid) {
}

/**
* Build the table from the fetched data.
*
* Take the data returned from the db_query and go through all the rows
* processing each col using either col_{columnname} method or other_cols
* method or if other_cols returns NULL then put the data straight into the
Expand All @@ -2075,18 +2077,13 @@ function __construct($uniqueid) {
* After calling this function, don't forget to call close_recordset.
*/
public function build_table() {

if ($this->rawdata instanceof \Traversable && !$this->rawdata->valid()) {
return;
}
if (!$this->rawdata) {
return;
}

foreach ($this->rawdata as $row) {
$formattedrow = $this->format_row($row);
$this->add_data_keyed($formattedrow,
$this->get_row_class($row));
$this->add_data_keyed($formattedrow, $this->get_row_class($row));
}
}

Expand Down

0 comments on commit ff4d5f3

Please sign in to comment.