فهرست منبع

use a loop instead of recursion in CursorBasedIterator

servers with large sets of keys will cause memory and stack exhaustion if recursion is used
Gwilym Evans 10 سال پیش
والد
کامیت
f05cb1b46d
1فایلهای تغییر یافته به همراه15 افزوده شده و 11 حذف شده
  1. 15 11
      lib/Predis/Collection/Iterator/CursorBasedIterator.php

+ 15 - 11
lib/Predis/Collection/Iterator/CursorBasedIterator.php

@@ -165,17 +165,21 @@ abstract class CursorBasedIterator implements Iterator
      */
     public function next()
     {
-        if (!$this->elements && $this->fetchmore) {
-            $this->fetch();
-        }
-
-        if ($this->elements) {
-            $this->extractNext();
-        } elseif ($this->cursor) {
-            $this->next();
-        } else {
-            $this->valid = false;
-        }
+        do {
+            $more = false;
+
+            if (!$this->elements && $this->fetchmore) {
+                $this->fetch();
+            }
+
+            if ($this->elements) {
+                $this->extractNext();
+            } elseif ($this->cursor) {
+                $more = true;
+            } else {
+                $this->valid = false;
+            }
+        } while ($more);
     }
 
     /**