colder                                   Tue, 27 Apr 2010 04:57:48 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=298633

Log:
Fix #49723 (Skip seek when unnecessary)

Bug: http://bugs.php.net/49723 (Assigned) LimitIterator with empty ArrayIterator
      
Changed paths:
    U   php/php-src/branches/PHP_5_2/ext/spl/spl_iterators.c
    A   php/php-src/branches/PHP_5_2/ext/spl/tests/bug49723.phpt
    U   php/php-src/branches/PHP_5_3/ext/spl/spl_iterators.c
    A   php/php-src/branches/PHP_5_3/ext/spl/tests/bug49723.phpt
    U   php/php-src/trunk/ext/spl/spl_iterators.c
    A   php/php-src/trunk/ext/spl/tests/bug49723.phpt

Modified: php/php-src/branches/PHP_5_2/ext/spl/spl_iterators.c
===================================================================
--- php/php-src/branches/PHP_5_2/ext/spl/spl_iterators.c        2010-04-27 
01:33:35 UTC (rev 298632)
+++ php/php-src/branches/PHP_5_2/ext/spl/spl_iterators.c        2010-04-27 
04:57:48 UTC (rev 298633)
@@ -1738,7 +1738,7 @@
                zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0 
TSRMLS_CC, "Cannot seek to %ld which is behind offset %ld plus count %ld", pos, 
intern->u.limit.offset, intern->u.limit.count);
                return;
        }
-       if (instanceof_function(intern->inner.ce, spl_ce_SeekableIterator 
TSRMLS_CC)) {
+       if (pos != intern->current.pos && instanceof_function(intern->inner.ce, 
spl_ce_SeekableIterator TSRMLS_CC)) {
                MAKE_STD_ZVAL(zpos);
                ZVAL_LONG(zpos, pos);
                spl_dual_it_free(intern TSRMLS_CC);

Added: php/php-src/branches/PHP_5_2/ext/spl/tests/bug49723.phpt
===================================================================
--- php/php-src/branches/PHP_5_2/ext/spl/tests/bug49723.phpt                    
        (rev 0)
+++ php/php-src/branches/PHP_5_2/ext/spl/tests/bug49723.phpt    2010-04-27 
04:57:48 UTC (rev 298633)
@@ -0,0 +1,16 @@
+--TEST--
+LimitIterator: do not seek if not needed
+--FILE--
+<?php
+
+$it = new ArrayIterator(array());
+
+$lit = new LimitIterator($it, 0, 5);
+
+foreach ($lit as $v) {
+    echo $v;
+}
+?>
+===DONE===
+--EXPECT--
+===DONE===

Modified: php/php-src/branches/PHP_5_3/ext/spl/spl_iterators.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/spl/spl_iterators.c        2010-04-27 
01:33:35 UTC (rev 298632)
+++ php/php-src/branches/PHP_5_3/ext/spl/spl_iterators.c        2010-04-27 
04:57:48 UTC (rev 298633)
@@ -2080,7 +2080,7 @@
                zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0 
TSRMLS_CC, "Cannot seek to %ld which is behind offset %ld plus count %ld", pos, 
intern->u.limit.offset, intern->u.limit.count);
                return;
        }
-       if (instanceof_function(intern->inner.ce, spl_ce_SeekableIterator 
TSRMLS_CC)) {
+       if (pos != intern->current.pos && instanceof_function(intern->inner.ce, 
spl_ce_SeekableIterator TSRMLS_CC)) {
                MAKE_STD_ZVAL(zpos);
                ZVAL_LONG(zpos, pos);
                spl_dual_it_free(intern TSRMLS_CC);

Added: php/php-src/branches/PHP_5_3/ext/spl/tests/bug49723.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/spl/tests/bug49723.phpt                    
        (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/spl/tests/bug49723.phpt    2010-04-27 
04:57:48 UTC (rev 298633)
@@ -0,0 +1,16 @@
+--TEST--
+LimitIterator: do not seek if not needed
+--FILE--
+<?php
+
+$it = new ArrayIterator(array());
+
+$lit = new LimitIterator($it, 0, 5);
+
+foreach ($lit as $v) {
+    echo $v;
+}
+?>
+===DONE===
+--EXPECT--
+===DONE===

Modified: php/php-src/trunk/ext/spl/spl_iterators.c
===================================================================
--- php/php-src/trunk/ext/spl/spl_iterators.c   2010-04-27 01:33:35 UTC (rev 
298632)
+++ php/php-src/trunk/ext/spl/spl_iterators.c   2010-04-27 04:57:48 UTC (rev 
298633)
@@ -2080,7 +2080,7 @@
                zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0 
TSRMLS_CC, "Cannot seek to %ld which is behind offset %ld plus count %ld", pos, 
intern->u.limit.offset, intern->u.limit.count);
                return;
        }
-       if (instanceof_function(intern->inner.ce, spl_ce_SeekableIterator 
TSRMLS_CC)) {
+       if (pos != intern->current.pos && instanceof_function(intern->inner.ce, 
spl_ce_SeekableIterator TSRMLS_CC)) {
                MAKE_STD_ZVAL(zpos);
                ZVAL_LONG(zpos, pos);
                spl_dual_it_free(intern TSRMLS_CC);

Added: php/php-src/trunk/ext/spl/tests/bug49723.phpt
===================================================================
--- php/php-src/trunk/ext/spl/tests/bug49723.phpt                               
(rev 0)
+++ php/php-src/trunk/ext/spl/tests/bug49723.phpt       2010-04-27 04:57:48 UTC 
(rev 298633)
@@ -0,0 +1,16 @@
+--TEST--
+LimitIterator: do not seek if not needed
+--FILE--
+<?php
+
+$it = new ArrayIterator(array());
+
+$lit = new LimitIterator($it, 0, 5);
+
+foreach ($lit as $v) {
+    echo $v;
+}
+?>
+===DONE===
+--EXPECT--
+===DONE===

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to