public static function fromItems(Traversable $arr) { // We can only do it this way if we can count it if ($arr instanceof Countable) { $sfa = new SplFixedArray(count($arr)); foreach ($arr as $i => $el) { $sfa[$i] = $el; } return new static($sfa); } // If we can't count it, it's simplest to iterate into an array first return static::fromArray(iterator_to_array($arr)); }
public function testLoadBigSet() { $startMem = ini_get('memory_limit'); ini_set('memory_limit', '50M'); // Big $bigSet = ImmArray::fromItems(new MD5Iterator(200000)); $this->assertCount(200000, $bigSet); ini_set('memory_limit', $startMem); }