use a loop instead of recursion in CursorBasedIterator

servers with large sets of keys will cause memory and stack exhaustion if recursion is used
This commit is contained in:
Gwilym Evans
2014-06-26 12:55:01 +10:00
parent 4db00173f3
commit f05cb1b46d
@@ -165,17 +165,21 @@ abstract class CursorBasedIterator implements Iterator
*/
public function next()
{
if (!$this->elements && $this->fetchmore) {
$this->fetch();
}
do {
$more = false;
if ($this->elements) {
$this->extractNext();
} elseif ($this->cursor) {
$this->next();
} else {
$this->valid = false;
}
if (!$this->elements && $this->fetchmore) {
$this->fetch();
}
if ($this->elements) {
$this->extractNext();
} elseif ($this->cursor) {
$more = true;
} else {
$this->valid = false;
}
} while ($more);
}
/**