From f28289f92a7a9f6fa419903126997b23bb9185ea Mon Sep 17 00:00:00 2001 From: Matt Allan Date: Tue, 18 Dec 2018 10:35:07 -0500 Subject: [PATCH] Use a generator for Cells::getAllCacheKeys Using a generator reduces memory usage and improves performance when loading large spreadsheets. Closes #822 --- CHANGELOG.md | 1 + src/PhpSpreadsheet/Collection/Cells.php | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e82dce4..43aab409 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Fix VLOOKUP with exact matches - [#809](https://github.com/PHPOffice/PhpSpreadsheet/pull/809) - Support COUNTIFS multiple arguments - [#830](https://github.com/PHPOffice/PhpSpreadsheet/pull/830) - Change `libxml_disable_entity_loader()` as shortly as possible - [#819](https://github.com/PHPOffice/PhpSpreadsheet/pull/819) +- Improved memory usage and performance when loading large spreadsheets - [#822](https://github.com/PHPOffice/PhpSpreadsheet/pull/822) ## [1.5.2] - 2018-11-25 diff --git a/src/PhpSpreadsheet/Collection/Cells.php b/src/PhpSpreadsheet/Collection/Cells.php index b87b805e..80a43220 100644 --- a/src/PhpSpreadsheet/Collection/Cells.php +++ b/src/PhpSpreadsheet/Collection/Cells.php @@ -495,15 +495,12 @@ class Cells /** * Returns all known cache keys. * - * @return string[] + * @return \Generator|string[] */ private function getAllCacheKeys() { - $keys = []; foreach ($this->getCoordinates() as $coordinate) { - $keys[] = $this->cachePrefix . $coordinate; + yield $this->cachePrefix . $coordinate; } - - return $keys; } }