dmitry Wed, 18 Aug 2010 13:58:13 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=302442
Log: improved performance of @ (silence) operator Changed paths: U php/php-src/trunk/NEWS U php/php-src/trunk/Zend/zend_globals.h U php/php-src/trunk/Zend/zend_ini.c U php/php-src/trunk/Zend/zend_ini.h U php/php-src/trunk/Zend/zend_vm_def.h U php/php-src/trunk/Zend/zend_vm_execute.h
Modified: php/php-src/trunk/NEWS =================================================================== --- php/php-src/trunk/NEWS 2010-08-18 13:34:40 UTC (rev 302441) +++ php/php-src/trunk/NEWS 2010-08-18 13:58:13 UTC (rev 302442) @@ -26,6 +26,7 @@ flag any more. Thit is very rare and useless case. ZEND_FREE might be required after them instead. . improved performance of FastCGI request parsing + . improved performance of @ (silence) operator - Added concept of interned strings. All strings constants known at compile time are allocated in a single copy and never changed. (Dmitry) - Added an optimization which saves memory and emalloc/efree calls for empty Modified: php/php-src/trunk/Zend/zend_globals.h =================================================================== --- php/php-src/trunk/Zend/zend_globals.h 2010-08-18 13:34:40 UTC (rev 302441) +++ php/php-src/trunk/Zend/zend_globals.h 2010-08-18 13:58:13 UTC (rev 302442) @@ -69,7 +69,9 @@ } zend_declarables; typedef struct _zend_vm_stack *zend_vm_stack; +typedef struct _zend_ini_entry zend_ini_entry; + struct _zend_compiler_globals { zend_stack bp_stack; zend_stack switch_cond_stack; @@ -248,6 +250,7 @@ HashTable *ini_directives; HashTable *modified_ini_directives; + zend_ini_entry *error_reporting_ini_entry; zend_objects_store objects_store; zval *exception, *prev_exception; Modified: php/php-src/trunk/Zend/zend_ini.c =================================================================== --- php/php-src/trunk/Zend/zend_ini.c 2010-08-18 13:34:40 UTC (rev 302441) +++ php/php-src/trunk/Zend/zend_ini.c 2010-08-18 13:58:13 UTC (rev 302442) @@ -92,6 +92,7 @@ EG(ini_directives) = registered_zend_ini_directives; EG(modified_ini_directives) = NULL; + EG(error_reporting_ini_entry) = NULL; if (zend_hash_init_ex(registered_zend_ini_directives, 100, NULL, NULL, 1, 0) == FAILURE) { return FAILURE; } @@ -133,6 +134,7 @@ zend_ini_entry ini_entry; EG(modified_ini_directives) = NULL; + EG(error_reporting_ini_entry) = NULL; EG(ini_directives) = (HashTable *) malloc(sizeof(HashTable)); if (zend_hash_init_ex(EG(ini_directives), registered_zend_ini_directives->nNumOfElements, NULL, NULL, 1, 0) == FAILURE) { return FAILURE; Modified: php/php-src/trunk/Zend/zend_ini.h =================================================================== --- php/php-src/trunk/Zend/zend_ini.h 2010-08-18 13:34:40 UTC (rev 302441) +++ php/php-src/trunk/Zend/zend_ini.h 2010-08-18 13:58:13 UTC (rev 302442) @@ -57,8 +57,6 @@ #endif -typedef struct _zend_ini_entry zend_ini_entry; - #define ZEND_INI_MH(name) int name(zend_ini_entry *entry, char *new_value, uint new_value_length, void *mh_arg1, void *mh_arg2, void *mh_arg3, int stage TSRMLS_DC) #define ZEND_INI_DISP(name) void name(zend_ini_entry *ini_entry, int type) Modified: php/php-src/trunk/Zend/zend_vm_def.h =================================================================== --- php/php-src/trunk/Zend/zend_vm_def.h 2010-08-18 13:34:40 UTC (rev 302441) +++ php/php-src/trunk/Zend/zend_vm_def.h 2010-08-18 13:58:13 UTC (rev 302442) @@ -4520,7 +4520,30 @@ } if (EG(error_reporting)) { - zend_alter_ini_entry_ex("error_reporting", sizeof("error_reporting"), "0", 1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME, 1 TSRMLS_CC); + do { + EG(error_reporting) = 0; + if (!EG(error_reporting_ini_entry)) { + if (UNEXPECTED(zend_hash_find(EG(ini_directives), "error_reporting", sizeof("error_reporting"), (void **) &EG(error_reporting_ini_entry)) == FAILURE)) { + break; + } + } + if (!EG(error_reporting_ini_entry)->modified) { + if (!EG(modified_ini_directives)) { + ALLOC_HASHTABLE(EG(modified_ini_directives)); + zend_hash_init(EG(modified_ini_directives), 8, NULL, NULL, 0); + } + if (EXPECTED(zend_hash_add(EG(modified_ini_directives), "error_reporting", sizeof("error_reporting"), &EG(error_reporting_ini_entry), sizeof(zend_ini_entry*), NULL) == SUCCESS)) { + EG(error_reporting_ini_entry)->orig_value = EG(error_reporting_ini_entry)->value; + EG(error_reporting_ini_entry)->orig_value_length = EG(error_reporting_ini_entry)->value_length; + EG(error_reporting_ini_entry)->orig_modifiable = EG(error_reporting_ini_entry)->modifiable; + EG(error_reporting_ini_entry)->modified = 1; + } + } else if (EG(error_reporting_ini_entry)->value != EG(error_reporting_ini_entry)->orig_value) { + efree(EG(error_reporting_ini_entry)->value); + } + EG(error_reporting_ini_entry)->value = estrndup("0", sizeof("0")-1); + EG(error_reporting_ini_entry)->value_length = sizeof("0")-1; + } while (0); } CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); @@ -4542,9 +4565,18 @@ if (!EG(error_reporting) && Z_LVAL(EX_T(opline->op1.var).tmp_var) != 0) { Z_TYPE(restored_error_reporting) = IS_LONG; Z_LVAL(restored_error_reporting) = Z_LVAL(EX_T(opline->op1.var).tmp_var); + EG(error_reporting) = Z_LVAL(restored_error_reporting); convert_to_string(&restored_error_reporting); - zend_alter_ini_entry_ex("error_reporting", sizeof("error_reporting"), Z_STRVAL(restored_error_reporting), Z_STRLEN(restored_error_reporting), ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME, 1 TSRMLS_CC); - zendi_zval_dtor(restored_error_reporting); + if (EXPECTED(EG(error_reporting_ini_entry) != NULL)) { + if (EXPECTED(EG(error_reporting_ini_entry)->modified && + EG(error_reporting_ini_entry)->value != EG(error_reporting_ini_entry)->orig_value)) { + efree(EG(error_reporting_ini_entry)->value); + } + EG(error_reporting_ini_entry)->value = Z_STRVAL(restored_error_reporting); + EG(error_reporting_ini_entry)->value_length = Z_STRLEN(restored_error_reporting); + } else { + zendi_zval_dtor(restored_error_reporting); + } } if (EX(old_error_reporting) == &EX_T(opline->op1.var).tmp_var) { EX(old_error_reporting) = NULL; Modified: php/php-src/trunk/Zend/zend_vm_execute.h =================================================================== --- php/php-src/trunk/Zend/zend_vm_execute.h 2010-08-18 13:34:40 UTC (rev 302441) +++ php/php-src/trunk/Zend/zend_vm_execute.h 2010-08-18 13:58:13 UTC (rev 302442) @@ -848,7 +848,30 @@ } if (EG(error_reporting)) { - zend_alter_ini_entry_ex("error_reporting", sizeof("error_reporting"), "0", 1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME, 1 TSRMLS_CC); + do { + EG(error_reporting) = 0; + if (!EG(error_reporting_ini_entry)) { + if (UNEXPECTED(zend_hash_find(EG(ini_directives), "error_reporting", sizeof("error_reporting"), (void **) &EG(error_reporting_ini_entry)) == FAILURE)) { + break; + } + } + if (!EG(error_reporting_ini_entry)->modified) { + if (!EG(modified_ini_directives)) { + ALLOC_HASHTABLE(EG(modified_ini_directives)); + zend_hash_init(EG(modified_ini_directives), 8, NULL, NULL, 0); + } + if (EXPECTED(zend_hash_add(EG(modified_ini_directives), "error_reporting", sizeof("error_reporting"), &EG(error_reporting_ini_entry), sizeof(zend_ini_entry*), NULL) == SUCCESS)) { + EG(error_reporting_ini_entry)->orig_value = EG(error_reporting_ini_entry)->value; + EG(error_reporting_ini_entry)->orig_value_length = EG(error_reporting_ini_entry)->value_length; + EG(error_reporting_ini_entry)->orig_modifiable = EG(error_reporting_ini_entry)->modifiable; + EG(error_reporting_ini_entry)->modified = 1; + } + } else if (EG(error_reporting_ini_entry)->value != EG(error_reporting_ini_entry)->orig_value) { + efree(EG(error_reporting_ini_entry)->value); + } + EG(error_reporting_ini_entry)->value = estrndup("0", sizeof("0")-1); + EG(error_reporting_ini_entry)->value_length = sizeof("0")-1; + } while (0); } CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); @@ -6898,9 +6921,18 @@ if (!EG(error_reporting) && Z_LVAL(EX_T(opline->op1.var).tmp_var) != 0) { Z_TYPE(restored_error_reporting) = IS_LONG; Z_LVAL(restored_error_reporting) = Z_LVAL(EX_T(opline->op1.var).tmp_var); + EG(error_reporting) = Z_LVAL(restored_error_reporting); convert_to_string(&restored_error_reporting); - zend_alter_ini_entry_ex("error_reporting", sizeof("error_reporting"), Z_STRVAL(restored_error_reporting), Z_STRLEN(restored_error_reporting), ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME, 1 TSRMLS_CC); - zendi_zval_dtor(restored_error_reporting); + if (EXPECTED(EG(error_reporting_ini_entry) != NULL)) { + if (EXPECTED(EG(error_reporting_ini_entry)->modified && + EG(error_reporting_ini_entry)->value != EG(error_reporting_ini_entry)->orig_value)) { + efree(EG(error_reporting_ini_entry)->value); + } + EG(error_reporting_ini_entry)->value = Z_STRVAL(restored_error_reporting); + EG(error_reporting_ini_entry)->value_length = Z_STRLEN(restored_error_reporting); + } else { + zendi_zval_dtor(restored_error_reporting); + } } if (EX(old_error_reporting) == &EX_T(opline->op1.var).tmp_var) { EX(old_error_reporting) = NULL;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php