Permalink
Browse files

- no unneccessary retval initialization

- new c-level iterator handler invalidate_current that is optionally
  used to clear internal caching like in implementation of Iterator
  • Loading branch information...
1 parent e780c42 commit e1cd098925007713926506f44681fbff7f9e7d28 Marcus Boerger committed Apr 27, 2004
Showing with 9 additions and 17 deletions.
  1. +6 −15 Zend/zend_interfaces.c
  2. +0 −2 Zend/zend_interfaces.h
  3. +3 −0 Zend/zend_iterators.h
View
@@ -108,7 +108,7 @@ static zval *zend_user_it_new_iterator(zend_class_entry *ce, zval *object TSRMLS
/* }}} */
/* {{{ zend_user_it_dtor */
-ZEND_API void zend_user_it_free_current(zend_object_iterator *_iter TSRMLS_DC)
+static void zend_user_it_invalidate_current(zend_object_iterator *_iter TSRMLS_DC)
{
zend_user_iterator *iter = (zend_user_iterator*)_iter;
@@ -125,10 +125,7 @@ static void zend_user_it_dtor(zend_object_iterator *_iter TSRMLS_DC)
zend_user_iterator *iter = (zend_user_iterator*)_iter;
zval *object = (zval*)iter->it.data;
- if (iter->value) {
- zval_ptr_dtor(&iter->value);
- iter->value = NULL;
- }
+ zend_user_it_invalidate_current(iter TSRMLS_CC);
zval_ptr_dtor(&object);
efree(iter);
}
@@ -187,8 +184,6 @@ static int zend_user_it_get_current_key(zend_object_iterator *_iter, char **str_
zend_call_method_with_0_params(&object, iter->ce, &iter->ce->iterator_funcs.zf_key, "key", &retval);
if (!retval) {
- *str_key = "";
- *str_key_len = 0;
*int_key = 0;
zend_error(E_WARNING, "Nothing returned from %s::key()", iter->ce->name);
return HASH_KEY_IS_LONG;
@@ -197,16 +192,13 @@ static int zend_user_it_get_current_key(zend_object_iterator *_iter, char **str_
default:
zend_error(E_WARNING, "Illegal type returned from %s::key()", iter->ce->name);
case IS_NULL:
- *str_key = "";
- *str_key_len = 0;
*int_key = 0;
zval_ptr_dtor(&retval);
return HASH_KEY_IS_LONG;
case IS_STRING:
*str_key = estrndup(retval->value.str.val, retval->value.str.len);
*str_key_len = retval->value.str.len+1;
- *int_key = 0;
zval_ptr_dtor(&retval);
return HASH_KEY_IS_STRING;
@@ -232,10 +224,7 @@ static void zend_user_it_move_forward(zend_object_iterator *_iter TSRMLS_DC)
zend_user_iterator *iter = (zend_user_iterator*)_iter;
zval *object = (zval*)iter->it.data;
- if (iter->value) {
- zval_ptr_dtor(&iter->value);
- iter->value = NULL;
- }
+ zend_user_it_invalidate_current(iter TSRMLS_CC);
zend_call_method_with_0_params(&object, iter->ce, &iter->ce->iterator_funcs.zf_next, "next", NULL);
}
/* }}} */
@@ -246,6 +235,7 @@ static void zend_user_it_rewind(zend_object_iterator *_iter TSRMLS_DC)
zend_user_iterator *iter = (zend_user_iterator*)_iter;
zval *object = (zval*)iter->it.data;
+ zend_user_it_invalidate_current(iter TSRMLS_CC);
zend_call_method_with_0_params(&object, iter->ce, &iter->ce->iterator_funcs.zf_rewind, "rewind", NULL);
}
/* }}} */
@@ -256,7 +246,8 @@ zend_object_iterator_funcs zend_interface_iterator_funcs_iterator = {
zend_user_it_get_current_data,
zend_user_it_get_current_key,
zend_user_it_move_forward,
- zend_user_it_rewind
+ zend_user_it_rewind,
+ zend_user_it_invalidate_current
};
/* {{{ zend_user_it_get_iterator */
View
@@ -37,8 +37,6 @@ typedef struct _zend_user_iterator {
zval *value;
} zend_user_iterator;
-ZEND_API void zend_user_it_free_current(zend_object_iterator *_iter TSRMLS_DC);
-
ZEND_API zval* zend_call_method(zval **object_pp, zend_class_entry *obj_ce, zend_function **fn_proxy, char *function_name, int function_name_len, zval **retval_ptr_ptr, int param_count, zval* arg1, zval* arg2 TSRMLS_DC);
#define zend_call_method_with_0_params(obj, obj_ce, fn_proxy, function_name, retval) \
View
@@ -46,6 +46,9 @@ typedef struct _zend_object_iterator_funcs {
/* rewind to start of data (optional, may be NULL) */
void (*rewind)(zend_object_iterator *iter TSRMLS_DC);
+
+ /* invalidate current value/key (optional, may be NULL) */
+ void (*invalidate_current)(zend_object_iterator *iter TSRMLS_DC);
} zend_object_iterator_funcs;
struct _zend_object_iterator {

0 comments on commit e1cd098

Please sign in to comment.