andrei          Tue Jul 11 17:59:47 2006 UTC

  Modified files:              
    /php-src/ext/unicode        unicode_iterators.c 
  Log:
  Make next() and previous() take optional step parameter and optimize
  return value usage.
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/unicode/unicode_iterators.c?r1=1.41&r2=1.42&diff_format=u
Index: php-src/ext/unicode/unicode_iterators.c
diff -u php-src/ext/unicode/unicode_iterators.c:1.41 
php-src/ext/unicode/unicode_iterators.c:1.42
--- php-src/ext/unicode/unicode_iterators.c:1.41        Tue Jul 11 17:48:14 2006
+++ php-src/ext/unicode/unicode_iterators.c     Tue Jul 11 17:59:46 2006
@@ -14,7 +14,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: unicode_iterators.c,v 1.41 2006/07/11 17:48:14 andrei Exp $ */
+/* $Id: unicode_iterators.c,v 1.42 2006/07/11 17:59:46 andrei Exp $ */
 
 /*
  * TODO
@@ -1035,11 +1035,25 @@
 
 PHP_METHOD(TextIterator, next)
 {
+       long i, step = 1;
        zval *object = getThis();
        text_iter_obj *intern = (text_iter_obj*) 
zend_object_store_get_object(object TSRMLS_CC);
 
-       iter_ops[intern->type]->next(intern, intern->flags TSRMLS_CC);
-       RETURN_LONG(iter_ops[intern->type]->offset(intern, intern->flags 
TSRMLS_CC));
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &step) == 
FAILURE) {
+               return;
+       }
+
+       if (step <= 0) {
+               step = 1;
+       }
+
+       for (i = 0; i < step; i++) {
+               iter_ops[intern->type]->next(intern, intern->flags TSRMLS_CC);
+       }
+
+       if (return_value_used) {
+               RETURN_LONG(iter_ops[intern->type]->offset(intern, 
intern->flags TSRMLS_CC));
+       }
 }
 
 PHP_METHOD(TextIterator, key)
@@ -1088,13 +1102,26 @@
 
 PHP_METHOD(TextIterator, previous)
 {
-       long flags;
+       long flags, i, step = 1;
        zval *object = getThis();
        text_iter_obj *intern = (text_iter_obj*) 
zend_object_store_get_object(object TSRMLS_CC);
 
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &step) == 
FAILURE) {
+               return;
+       }
+
+       if (step <= 0) {
+               step = 1;
+       }
        flags = intern->flags ^ ITER_REVERSE;
-       iter_ops[intern->type]->next(intern, flags TSRMLS_CC);
-       RETURN_LONG(iter_ops[intern->type]->offset(intern, flags TSRMLS_CC));
+
+       for (i = 0; i < step; i++) {
+               iter_ops[intern->type]->next(intern, flags TSRMLS_CC);
+       }
+
+       if (return_value_used) {
+               RETURN_LONG(iter_ops[intern->type]->offset(intern, flags 
TSRMLS_CC));
+       }
 }
 
 PHP_METHOD(TextIterator, following)

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

Reply via email to