diff options
author | Etienne Kneuss <colder@php.net> | 2008-07-06 23:45:56 +0000 |
---|---|---|
committer | Etienne Kneuss <colder@php.net> | 2008-07-06 23:45:56 +0000 |
commit | 0eea0a059e66a6b5f2b66e37350c7b8c68414c1e (patch) | |
tree | 47dfad5de4b147787febdc72a85512288ccdf2d5 /ext/spl/spl_heap.c | |
parent | 7599f55fdf6a47bc11afa005d2ae71a89e978e4f (diff) | |
download | php-git-0eea0a059e66a6b5f2b66e37350c7b8c68414c1e.tar.gz |
MFH: First part of count/handlers related fixes
Diffstat (limited to 'ext/spl/spl_heap.c')
-rw-r--r-- | ext/spl/spl_heap.c | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/ext/spl/spl_heap.c b/ext/spl/spl_heap.c index c810b15411..3c94eac853 100644 --- a/ext/spl/spl_heap.c +++ b/ext/spl/spl_heap.c @@ -75,6 +75,7 @@ struct _spl_heap_object { int flags; zend_class_entry *ce_get_iterator; zend_function *fptr_cmp; + zend_function *fptr_count; }; /* define an overloaded iterator structure */ @@ -441,10 +442,13 @@ static zend_object_value spl_heap_object_new_ex(zend_class_entry *class_type, sp if (inherited) { zend_hash_find(&class_type->function_table, "compare", sizeof("compare"), (void **) &intern->fptr_cmp); - if (intern->fptr_cmp->common.scope == parent) { intern->fptr_cmp = NULL; } + zend_hash_find(&class_type->function_table, "count", sizeof("count"), (void **) &intern->fptr_count); + if (intern->fptr_count->common.scope == parent) { + intern->fptr_count = NULL; + } } return retval; @@ -480,6 +484,21 @@ static int spl_heap_object_count_elements(zval *object, long *count TSRMLS_DC) / { spl_heap_object *intern = (spl_heap_object*)zend_object_store_get_object(object TSRMLS_CC); + if (intern->fptr_count) { + zval *rv; + zend_call_method_with_0_params(&object, intern->std.ce, &intern->fptr_count, "count", &rv); + if (rv) { + zval_ptr_dtor(&intern->retval); + MAKE_STD_ZVAL(intern->retval); + ZVAL_ZVAL(intern->retval, rv, 1, 1); + convert_to_long(intern->retval); + *count = (long) Z_LVAL_P(intern->retval); + return SUCCESS; + } + *count = 0; + return FAILURE; + } + *count = spl_ptr_heap_count(intern->heap); return SUCCESS; @@ -545,12 +564,13 @@ static HashTable* spl_pqueue_object_get_debug_info(zval *obj, int *is_temp TSRML SPL_METHOD(SplHeap, count) { long count; + spl_heap_object *intern = (spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { return; } - spl_heap_object_count_elements(getThis(), &count TSRMLS_CC); + count = spl_ptr_heap_count(intern->heap); RETURN_LONG(count); } /* }}} */ @@ -559,14 +579,13 @@ SPL_METHOD(SplHeap, count) Return true if the heap is empty. */ SPL_METHOD(SplHeap, isEmpty) { - long count; + spl_heap_object *intern = (spl_heap_object*)zend_object_store_get_object(getThis() TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "") == FAILURE) { return; } - spl_heap_object_count_elements(getThis(), &count TSRMLS_CC); - RETURN_BOOL(count==0); + RETURN_BOOL(spl_ptr_heap_count(intern->heap)==0); } /* }}} */ |