summaryrefslogtreecommitdiff
path: root/ext/standard/array.c
diff options
context:
space:
mode:
authorXinchen Hui <laruence@gmail.com>2015-11-23 06:12:03 -0800
committerXinchen Hui <laruence@gmail.com>2015-11-23 06:12:03 -0800
commit6313e16a0472d42a2056364b1aacd7798d500b75 (patch)
tree75b8462f49a2ffaabf3d6458f2246392d3ac59bb /ext/standard/array.c
parent8c51578c81c04b6e9efa03b75e9473cfa5ad550f (diff)
downloadphp-git-6313e16a0472d42a2056364b1aacd7798d500b75.tar.gz
Improved fix for bug (count on symbol table)
Diffstat (limited to 'ext/standard/array.c')
-rw-r--r--ext/standard/array.c41
1 files changed, 3 insertions, 38 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c
index df9cc563ac..79c9ab6207 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -757,41 +757,6 @@ PHP_FUNCTION(ksort)
}
/* }}} */
-static uint32_t php_array_recalc_elements(HashTable *ht) /* {{{ */
-{
- zval *val;
- uint32_t num = ht->nNumOfElements;
-
- ZEND_HASH_FOREACH_VAL(ht, val) {
- if (Z_TYPE_P(val) == IS_UNDEF) continue;
- if (Z_TYPE_P(val) == IS_INDIRECT) {
- if (Z_TYPE_P(Z_INDIRECT_P(val)) == IS_UNDEF) {
- num--;
- }
- }
- } ZEND_HASH_FOREACH_END();
- return num;
-}
-/* }}} */
-
-static uint32_t php_array_num_elements(zval *arr) /* {{{ */
-{
- uint32_t num;
- HashTable *ht = Z_ARRVAL_P(arr);
- if (UNEXPECTED(Z_SYMBOLTABLE_P(arr))) {
- num = php_array_recalc_elements(ht);
- } else if (UNEXPECTED(ht->u.v.flags & HASH_FLAG_HAS_EMPTY_IND)) {
- num = php_array_recalc_elements(ht);
- if (UNEXPECTED(ht->nNumOfElements == num)) {
- ht->u.v.flags &= ~HASH_FLAG_HAS_EMPTY_IND;
- }
- } else {
- num = zend_hash_num_elements(ht);
- }
- return num;
-}
-/* }}} */
-
PHPAPI zend_long php_count_recursive(zval *array, zend_long mode) /* {{{ */
{
zend_long cnt = 0;
@@ -803,7 +768,7 @@ PHPAPI zend_long php_count_recursive(zval *array, zend_long mode) /* {{{ */
return 0;
}
- cnt = php_array_num_elements(array);
+ cnt = zend_array_count(Z_ARRVAL_P(array));
if (mode == COUNT_RECURSIVE) {
if (ZEND_HASH_APPLY_PROTECTION(Z_ARRVAL_P(array))) {
Z_ARRVAL_P(array)->u.v.nApplyCount++;
@@ -848,7 +813,7 @@ PHP_FUNCTION(count)
RETURN_LONG(0);
break;
case IS_ARRAY:
- cnt = php_array_num_elements(array);
+ cnt = zend_array_count(Z_ARRVAL_P(array));
if (mode == COUNT_RECURSIVE) {
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array), element) {
ZVAL_DEREF(element);
@@ -5193,7 +5158,7 @@ PHP_FUNCTION(array_filter)
}
}
- ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(array), num_key, string_key, operand) {
+ ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(array), num_key, string_key, operand) {
if (have_callback) {
if (use_type) {
/* Set up the key */