helly Thu May 6 04:57:21 2004 EDT
Modified files:
/php-src/ext/spl spl_array.c
Log:
Count support for ArrayIterator & ArrayObject
http://cvs.php.net/diff.php/php-src/ext/spl/spl_array.c?r1=1.45&r2=1.46&ty=u
Index: php-src/ext/spl/spl_array.c
diff -u php-src/ext/spl/spl_array.c:1.45 php-src/ext/spl/spl_array.c:1.46
--- php-src/ext/spl/spl_array.c:1.45 Thu Apr 29 18:52:49 2004
+++ php-src/ext/spl/spl_array.c Thu May 6 04:57:20 2004
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: spl_array.c,v 1.45 2004/04/29 22:52:49 helly Exp $ */
+/* $Id: spl_array.c,v 1.46 2004/05/06 08:57:20 helly Exp $ */
#ifdef HAVE_CONFIG_H
# include "config.h"
@@ -614,31 +614,6 @@
}
/* }}} */
-/* {{{ PHP_MINIT_FUNCTION(spl_array) */
-PHP_MINIT_FUNCTION(spl_array)
-{
- REGISTER_SPL_STD_CLASS_EX(ArrayObject, spl_array_object_new,
spl_funcs_ArrayObject);
- zend_class_implements(spl_ce_ArrayObject TSRMLS_CC, 1, zend_ce_aggregate);
- zend_class_implements(spl_ce_ArrayObject TSRMLS_CC, 1, zend_ce_arrayaccess);
- memcpy(&spl_handler_ArrayObject, zend_get_std_object_handlers(),
sizeof(zend_object_handlers));
- spl_handler_ArrayObject.clone_obj = spl_array_object_clone;
- spl_handler_ArrayObject.read_dimension = spl_array_read_dimension;
- spl_handler_ArrayObject.write_dimension = spl_array_write_dimension;
- spl_handler_ArrayObject.unset_dimension = spl_array_unset_dimension;
- spl_handler_ArrayObject.has_dimension = spl_array_has_dimension;
- spl_handler_ArrayObject.get_properties = spl_array_get_properties;
-
- REGISTER_SPL_STD_CLASS_EX(ArrayIterator, spl_array_object_new,
spl_funcs_ArrayIterator);
- zend_class_implements(spl_ce_ArrayIterator TSRMLS_CC, 1, zend_ce_iterator);
- zend_class_implements(spl_ce_ArrayIterator TSRMLS_CC, 1, zend_ce_arrayaccess);
- REGISTER_SPL_IMPLEMENTS(ArrayIterator, SeekableIterator);
- memcpy(&spl_handler_ArrayIterator, &spl_handler_ArrayObject,
sizeof(zend_object_handlers));
- spl_ce_ArrayIterator->get_iterator = spl_array_get_iterator;
-
- return SUCCESS;
-}
-/* }}} */
-
/* {{{ proto void ArrayObject::__construct(array|object ar = array())
proto void ArrayIterator::__construct(array|object ar = array())
Cronstructs a new array iterator from a path. */
@@ -744,36 +719,47 @@
while (position-- > 0 && spl_array_next(intern TSRMLS_CC));
} /* }}} */
-/* {{{ proto int ArrayObject::count()
- proto int ArrayIterator::count()
- Return the number of elements in the Iterator. */
-SPL_METHOD(Array, count)
+int spl_array_object_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ */
{
- zval *object = getThis();
+ *count = 0;
+
spl_array_object *intern =
(spl_array_object*)zend_object_store_get_object(object TSRMLS_CC);
HashTable *aht = HASH_OF(intern->array);
HashPosition pos;
- long cnt;
if (!aht) {
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside
object and is no longer an array");
- RETURN_LONG(0);
+ *count = 0;
+ return FAILURE;
}
if (Z_TYPE_P(intern->array) == IS_OBJECT) {
+ /* We need to store the 'pos' since we'll modify it in the functions
+ * we're going to call and which do not support 'pos' as parameter. */
pos = intern->pos;
- cnt = 0;
+ *count = 0;
zend_hash_internal_pointer_reset_ex(aht, &intern->pos);
while(intern->pos) {
- cnt++;
+ (*count)++;
spl_array_next(intern TSRMLS_CC);
}
intern->pos = pos;
- RETURN_LONG(cnt);
+ return SUCCESS;
} else {
- RETURN_LONG(zend_hash_num_elements(aht));
+ *count = zend_hash_num_elements(aht);
+ return SUCCESS;
}
-
+} /* }}} */
+
+/* {{{ proto int ArrayObject::count()
+ proto int ArrayIterator::count()
+ Return the number of elements in the Iterator. */
+SPL_METHOD(Array, count)
+{
+ long count;
+
+ spl_array_object_count_elements(getThis(), &count TSRMLS_CC);
+ RETURN_LONG(count);
} /* }}} */
/* {{{ proto mixed|NULL ArrayIterator::current()
@@ -880,6 +866,32 @@
}
/* }}} */
+/* {{{ PHP_MINIT_FUNCTION(spl_array) */
+PHP_MINIT_FUNCTION(spl_array)
+{
+ REGISTER_SPL_STD_CLASS_EX(ArrayObject, spl_array_object_new,
spl_funcs_ArrayObject);
+ zend_class_implements(spl_ce_ArrayObject TSRMLS_CC, 1, zend_ce_aggregate);
+ zend_class_implements(spl_ce_ArrayObject TSRMLS_CC, 1, zend_ce_arrayaccess);
+ memcpy(&spl_handler_ArrayObject, zend_get_std_object_handlers(),
sizeof(zend_object_handlers));
+ spl_handler_ArrayObject.clone_obj = spl_array_object_clone;
+ spl_handler_ArrayObject.read_dimension = spl_array_read_dimension;
+ spl_handler_ArrayObject.write_dimension = spl_array_write_dimension;
+ spl_handler_ArrayObject.unset_dimension = spl_array_unset_dimension;
+ spl_handler_ArrayObject.has_dimension = spl_array_has_dimension;
+ spl_handler_ArrayObject.get_properties = spl_array_get_properties;
+ spl_handler_ArrayObject.count_elements = spl_array_object_count_elements;
+
+ REGISTER_SPL_STD_CLASS_EX(ArrayIterator, spl_array_object_new,
spl_funcs_ArrayIterator);
+ zend_class_implements(spl_ce_ArrayIterator TSRMLS_CC, 1, zend_ce_iterator);
+ zend_class_implements(spl_ce_ArrayIterator TSRMLS_CC, 1, zend_ce_arrayaccess);
+ REGISTER_SPL_IMPLEMENTS(ArrayIterator, SeekableIterator);
+ memcpy(&spl_handler_ArrayIterator, &spl_handler_ArrayObject,
sizeof(zend_object_handlers));
+ spl_ce_ArrayIterator->get_iterator = spl_array_get_iterator;
+
+ return SUCCESS;
+}
+/* }}} */
+
/*
* Local variables:
* tab-width: 4
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php