diff options
author | Dmitry Stogov <dmitry@zend.com> | 2014-12-23 19:08:28 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2014-12-23 19:08:28 +0300 |
commit | 106b1017d44580a37a191378f6cb03374b942807 (patch) | |
tree | efd8dcfb8bb446189563ca5991cc19ff1afcd52d /ext/standard/array.c | |
parent | c462ff7ac2514e22cef80aeb6fb733ebb22af8dc (diff) | |
download | php-git-106b1017d44580a37a191378f6cb03374b942807.tar.gz |
API for fast construction of packed arrays
Diffstat (limited to 'ext/standard/array.c')
-rw-r--r-- | ext/standard/array.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c index b9ccf5bd56..d2367385e0 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -2724,16 +2724,18 @@ PHP_FUNCTION(array_keys) } } else { array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(input))); - - /* Go through input array and add keys to the return array */ - ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(input), num_idx, str_idx, entry) { - if (str_idx) { - ZVAL_STR_COPY(&new_val, str_idx); - } else { - ZVAL_LONG(&new_val, num_idx); - } - zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), &new_val); - } ZEND_HASH_FOREACH_END(); + zend_hash_real_init(Z_ARRVAL_P(return_value), 1); + ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { + /* Go through input array and add keys to the return array */ + ZEND_HASH_FOREACH_KEY_VAL_IND(Z_ARRVAL_P(input), num_idx, str_idx, entry) { + if (str_idx) { + ZVAL_STR_COPY(&new_val, str_idx); + } else { + ZVAL_LONG(&new_val, num_idx); + } + ZEND_HASH_FILL_ADD(&new_val); + } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FILL_END(); } } /* }}} */ @@ -2751,12 +2753,15 @@ PHP_FUNCTION(array_values) /* Initialize return array */ array_init_size(return_value, zend_hash_num_elements(Z_ARRVAL_P(input))); + zend_hash_real_init(Z_ARRVAL_P(return_value), 1); /* Go through input array and add values to the return array */ - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(input), entry) { - zval_add_ref(entry); - zend_hash_next_index_insert_new(Z_ARRVAL_P(return_value), entry); - } ZEND_HASH_FOREACH_END(); + ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { + ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(input), entry) { + zval_add_ref(entry); + ZEND_HASH_FILL_ADD(entry); + } ZEND_HASH_FOREACH_END(); + } ZEND_HASH_FILL_END(); } /* }}} */ |