Skip to content

Commit

Permalink
Merge pull request #10307 from silverstripe-terraformers/feature/remo…
Browse files Browse the repository at this point in the history
…val-all-enhancement

ENH: RemoveAll() memory performance enhancement.
  • Loading branch information
GuySartorelli authored May 13, 2022
2 parents 995e5dc + b864c11 commit c0ff638
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ORM/DataList.php
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ public function shuffle()
*/
public function removeAll()
{
foreach ($this as $item) {
foreach ($this->getGenerator() as $item) {
$this->remove($item);
}
return $this;
Expand Down
11 changes: 11 additions & 0 deletions tests/php/ORM/DataListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,17 @@ public function testRemoveByID()
$this->assertNull($list->byID($id));
}

/**
* Test DataList->removeAll()
*/
public function testRemoveAll()
{
$list = Team::get();
$this->assertGreaterThan(0, $list->count());
$list->removeAll();
$this->assertCount(0, $list);
}

/**
* Test DataList->canSortBy()
*/
Expand Down

0 comments on commit c0ff638

Please sign in to comment.