diff options
author | Marcus Boerger <helly@php.net> | 2003-11-11 18:31:50 +0000 |
---|---|---|
committer | Marcus Boerger <helly@php.net> | 2003-11-11 18:31:50 +0000 |
commit | 91ab36096eee33551e5ff13ca837b42b41000ab8 (patch) | |
tree | b1cb8f0d76e16d6bfc791f86427b33036f3986a9 | |
parent | f8e6e5dad35112c45d6588afbace71957ce8c3ad (diff) | |
download | php-git-91ab36096eee33551e5ff13ca837b42b41000ab8.tar.gz |
Add shortcut interface SeekableIterator to LimitIterator
-rwxr-xr-x | ext/spl/examples/limititerator.inc | 8 | ||||
-rwxr-xr-x | ext/spl/examples/seekableiterator.inc | 16 |
2 files changed, 22 insertions, 2 deletions
diff --git a/ext/spl/examples/limititerator.inc b/ext/spl/examples/limititerator.inc index c1a19fedd9..cdc71e98ce 100755 --- a/ext/spl/examples/limititerator.inc +++ b/ext/spl/examples/limititerator.inc @@ -21,8 +21,12 @@ class LimitIterator implements Iterator { $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(); + } } } diff --git a/ext/spl/examples/seekableiterator.inc b/ext/spl/examples/seekableiterator.inc new file mode 100755 index 0000000000..157d2736f4 --- /dev/null +++ b/ext/spl/examples/seekableiterator.inc @@ -0,0 +1,16 @@ +<?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 |