From 74fd95e877c4ed095a2ad6fc051e40f2aea5bf86 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 25 Apr 2011 19:48:14 +0000 Subject: [PATCH] Rewrote endless creation of iterator instances to registry-based 'caching' --- .../pool/monitor/class_MonitorPoolIterator.php | 2 +- .../iterator/pool/tasks/class_TaskPoolIterator.php | 2 +- application/hub/main/pools/class_BasePool.php | 13 +++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/application/hub/main/iterator/pool/monitor/class_MonitorPoolIterator.php b/application/hub/main/iterator/pool/monitor/class_MonitorPoolIterator.php index 67a0f2319..72a2c2d86 100644 --- a/application/hub/main/iterator/pool/monitor/class_MonitorPoolIterator.php +++ b/application/hub/main/iterator/pool/monitor/class_MonitorPoolIterator.php @@ -23,7 +23,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class MonitorPoolIterator extends BaseIterator implements Iterator { +class MonitorPoolIterator extends BaseIterator implements Iterator, Registerable { /** * Key for the global list index */ diff --git a/application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php b/application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php index 3cee6a26d..f82dbf3ea 100644 --- a/application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php +++ b/application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php @@ -23,7 +23,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class TaskPoolIterator extends BaseIterator implements Iterator { +class TaskPoolIterator extends BaseIterator implements Iterator, Registerable { /** * Key for the global list index */ diff --git a/application/hub/main/pools/class_BasePool.php b/application/hub/main/pools/class_BasePool.php index 462d3ad1f..2e6c5c895 100644 --- a/application/hub/main/pools/class_BasePool.php +++ b/application/hub/main/pools/class_BasePool.php @@ -92,8 +92,17 @@ class BasePool extends BaseHubSystem implements Visitable { // Visit this pool $visitorInstance->visitPool($this); - // Get a new iterator instance - $iteratorInstance = ObjectFactory::createObjectByConfiguredName($visitorInstance->getVisitorMode() . '_pool_iterator_class', array($this->getPoolEntriesInstance())); + // Do we have a registry instance for this visitor's iterator? + if (Registry::getRegistry()->instanceExists($visitorInstance->getVisitorMode() . '_pool_iterator')) { + // Get the instance from registry + $iteratorInstance = Registry::getRegistry()->getInstance($visitorInstance->getVisitorMode() . '_pool_iterator'); + } else { + // Get a new iterator instance + $iteratorInstance = ObjectFactory::createObjectByConfiguredName($visitorInstance->getVisitorMode() . '_pool_iterator_class', array($this->getPoolEntriesInstance())); + + // Add it to the registry + Registry::getRegistry()->addInstance($visitorInstance->getVisitorMode() . '_pool_iterator', $iteratorInstance); + } // Reset the counter $iteratorInstance->rewind(); -- 2.39.5