{
$this->it->rewind();
$this->index = 0;
- while($this->index < $this->offset && $this->it->hasMore()) {
- $this->next();
+ if (is_a($this->it, 'SeekableIterator')) {
+ $this->index = $this->it->seek($this->offset);
+ } else {
+ while($this->index < $this->offset && $this->it->hasMore()) {
+ $this->next();
+ }
}
}
--- /dev/null
+<?php
+
+class SeekableIterator implements Iterator
+{
+ function seek($index) {
+ $this->rewind();
+ $position = 0;
+ while($position < $index && $this->it->hasMore()) {
+ $this->next();
+ $position++;
+ }
+ return $position;
+ }
+}
+
+?>
\ No newline at end of file