Skip to content

Commit

Permalink
Optimized shutdown sequence to iterate only over modified ini directives
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed May 15, 2006
1 parent b5cd968 commit 14cad8f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Zend/zend_globals.h
Expand Up @@ -227,6 +227,8 @@ struct _zend_executor_globals {
int lambda_count; int lambda_count;


HashTable *ini_directives; HashTable *ini_directives;
HashTable *modified_ini_directives;

zend_objects_store objects_store; zend_objects_store objects_store;
zval *exception; zval *exception;
zend_op *opline_before_exception; zend_op *opline_before_exception;
Expand Down
27 changes: 24 additions & 3 deletions Zend/zend_ini.c
Expand Up @@ -65,6 +65,12 @@ static int zend_restore_ini_entry_cb(zend_ini_entry *ini_entry, int stage TSRMLS
return 0; return 0;
} }


static int zend_restore_ini_entry_wrapper(zend_ini_entry **ini_entry TSRMLS_DC)
{
zend_restore_ini_entry_cb(*ini_entry, ZEND_INI_STAGE_DEACTIVATE TSRMLS_CC);
return 1;
}

/* /*
* Startup / shutdown * Startup / shutdown
*/ */
Expand All @@ -73,6 +79,7 @@ ZEND_API int zend_ini_startup(TSRMLS_D)
registered_zend_ini_directives = (HashTable *) malloc(sizeof(HashTable)); registered_zend_ini_directives = (HashTable *) malloc(sizeof(HashTable));


EG(ini_directives) = registered_zend_ini_directives; EG(ini_directives) = registered_zend_ini_directives;
EG(modified_ini_directives) = NULL;
if (zend_hash_init_ex(registered_zend_ini_directives, 100, NULL, NULL, 1, 0)==FAILURE) { if (zend_hash_init_ex(registered_zend_ini_directives, 100, NULL, NULL, 1, 0)==FAILURE) {
return FAILURE; return FAILURE;
} }
Expand All @@ -98,7 +105,12 @@ ZEND_API int zend_ini_global_shutdown(TSRMLS_D)


ZEND_API int zend_ini_deactivate(TSRMLS_D) ZEND_API int zend_ini_deactivate(TSRMLS_D)
{ {
zend_hash_apply_with_argument(EG(ini_directives), (apply_func_arg_t) zend_restore_ini_entry_cb, (void *) ZEND_INI_STAGE_DEACTIVATE TSRMLS_CC); if (EG(modified_ini_directives)) {
zend_hash_apply(EG(modified_ini_directives), (apply_func_t) zend_restore_ini_entry_wrapper TSRMLS_CC);
zend_hash_destroy(EG(modified_ini_directives));
FREE_HASHTABLE(EG(modified_ini_directives));
EG(modified_ini_directives) = NULL;
}
return SUCCESS; return SUCCESS;
} }


Expand Down Expand Up @@ -237,12 +249,17 @@ ZEND_API int zend_alter_ini_entry(char *name, uint name_length, char *new_value,
if (!ini_entry->modified) { if (!ini_entry->modified) {
ini_entry->orig_value = ini_entry->value; ini_entry->orig_value = ini_entry->value;
ini_entry->orig_value_length = ini_entry->value_length; ini_entry->orig_value_length = ini_entry->value_length;
ini_entry->modified = 1;
if (!EG(modified_ini_directives)) {
ALLOC_HASHTABLE(EG(modified_ini_directives));
zend_hash_init(EG(modified_ini_directives), 8, NULL, NULL, 0);
}
zend_hash_add(EG(modified_ini_directives), name, name_length, &ini_entry, sizeof(zend_ini_entry*), NULL);
} else { /* we already changed the value, free the changed value */ } else { /* we already changed the value, free the changed value */
efree(ini_entry->value); efree(ini_entry->value);
} }
ini_entry->value = duplicate; ini_entry->value = duplicate;
ini_entry->value_length = new_value_length; ini_entry->value_length = new_value_length;
ini_entry->modified = 1;
} else { } else {
efree(duplicate); efree(duplicate);
} }
Expand All @@ -260,7 +277,11 @@ ZEND_API int zend_restore_ini_entry(char *name, uint name_length, int stage)
return FAILURE; return FAILURE;
} }


zend_restore_ini_entry_cb(ini_entry, stage TSRMLS_CC); if (EG(modified_ini_directives)) {
zend_restore_ini_entry_cb(ini_entry, stage TSRMLS_CC);
zend_hash_del(EG(modified_ini_directives), name, name_length);
}

return SUCCESS; return SUCCESS;
} }


Expand Down

0 comments on commit 14cad8f

Please sign in to comment.