Use more compact representation for packed arrays.

- for packed arrays we store just an array of zvals without keys.
- the elements of packed array are accessible throuf as ht->arPacked[i]
  instead of ht->arData[i]
- in addition to general ZEND_HASH_FOREACH_* macros, we introduced similar
  familied for packed (ZEND_HASH_PACKED_FORECH_*) and real hashes
  (ZEND_HASH_MAP_FOREACH_*)
- introduced an additional family of macros to access elements of array
  (packed or real hashes) ZEND_ARRAY_ELEMET_SIZE, ZEND_ARRAY_ELEMET_EX,
  ZEND_ARRAY_ELEMET, ZEND_ARRAY_NEXT_ELEMENT, ZEND_ARRAY_PREV_ELEMENT
- zend_hash_minmax() prototype was changed to compare only values

Because of smaller data set, this patch may show performance improvement
on some apps and benchmarks that use packed arrays. (~1% on PHP-Parser)

TODO:
    - sapi/phpdbg needs special support for packed arrays (WATCH_ON_BUCKET).
    - zend_hash_sort_ex() may require converting packed arrays to hash.
This commit is contained in:
Dmitry Stogov 2021-11-03 15:18:26 +03:00
parent 0eb603e3bb
commit 90b7bde615
89 changed files with 3302 additions and 1664 deletions

View file

@ -157,7 +157,7 @@ void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf)
n = create_php_config(p, "merge_php_config");
/* copy old config */
#ifdef ZTS
ZEND_HASH_FOREACH_STR_KEY_VAL(&d->config, str, data) {
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(&d->config, str, data) {
zend_string *key;
zval *new_entry;
@ -195,7 +195,7 @@ void apply_config(void *dummy)
zend_string *str;
php_dir_entry *data;
ZEND_HASH_FOREACH_STR_KEY_PTR(&d->config, str, data) {
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&d->config, str, data) {
phpapdebug((stderr, "APPLYING (%s)(%s)\n", ZSTR_VAL(str), data->value));
if (zend_alter_ini_entry_chars(str, data->value, data->value_len, data->status, data->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE) == FAILURE) {
phpapdebug((stderr, "..FAILED\n"));

View file

@ -562,7 +562,7 @@ typedef struct {
zend_string *str;
php_conf_rec *c = ap_get_module_config(r->per_dir_config, &php_module);
ZEND_HASH_FOREACH_STR_KEY(&c->config, str) {
ZEND_HASH_MAP_FOREACH_STR_KEY(&c->config, str) {
zend_restore_ini_entry(str, ZEND_INI_STAGE_SHUTDOWN);
} ZEND_HASH_FOREACH_END();
}