Here is the implementation of get_iterated() (comments mine):
public function get_iterated($limit = NULL, $offset = NULL)
{
// get hold of object after it is cleared though call to get_row
$object = $this->get_clone();
// clears the query from the clone
$object->db->dm_call_method('_reset_select');
// clear the related query from the clone
$object->_query_related = array();
// REAL MAGIC starts here: Build iterator
$this->_dm_dataset_iterator = new DM_DatasetIterator($object, $this->get_raw($limit, $offset, TRUE));
return $this;
}
The real magic happens at the line:
$this->_dm_dataset_iterator = new DM_DatasetIterator($object, $this->get_raw($limit, $offset, TRUE));
The real speedy work is done by the DM_DatasetIterator class for the get_iterated() method because it implements an Iterator which are generally FAST. The class implements all the required methods that are required by the Iterator interface such as current(), key(), get(), etc
So overall there are two reasons why it is fast:
- The actual object is cleaned (query and related info)
- It is then passed to iterator which are fast
You might ask why iterators are fast? Well because they process data iteratively instead of buffering in memory.
Learn about here: