summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinchen Hui <laruence@php.net>2012-03-24 11:46:29 +0800
committerXinchen Hui <laruence@php.net>2012-03-24 11:54:50 +0800
commit4130f5a43c322270c11bf781829cea68a025183f (patch)
tree44c3d5b18b6e7d425b77f5877df9f1dc872859be
parent114d662d12aa9672cfd567a6db3624c25d5f4394 (diff)
downloadphp-git-4130f5a43c322270c11bf781829cea68a025183f.tar.gz
Improve set_exception_handler
Remove useless alloc/free and return_value copy while doing reset exception handler
-rw-r--r--NEWS1
-rw-r--r--Zend/zend_builtin_functions.c37
2 files changed, 20 insertions, 18 deletions
diff --git a/NEWS b/NEWS
index c0ba09159f..c2e812c1d3 100644
--- a/NEWS
+++ b/NEWS
@@ -38,6 +38,7 @@ PHP NEWS
. Fixed bug #60569 (Nullbyte truncates Exception $message). (Ilia)
. Fixed bug #52719 (array_walk_recursive crashes if third param of the
function is by reference). (Nikita Popov)
+ . Improve performance of set_exception handler while doing reset (Laruence)
- FPM
. Fixed bug #61430 (Transposed memset() params in sapi/fpm/fpm/fpm_shm.c).
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index b55231d0c6..29f9ed36bb 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -1585,41 +1585,42 @@ ZEND_FUNCTION(set_exception_handler)
{
zval *exception_handler;
char *exception_handler_name = NULL;
- zend_bool had_orig_exception_handler=0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &exception_handler) == FAILURE) {
return;
}
if (Z_TYPE_P(exception_handler) != IS_NULL) { /* NULL == unset */
+ zend_bool had_orig_exception_handler = 0;
+
if (!zend_is_callable(exception_handler, 0, &exception_handler_name TSRMLS_CC)) {
zend_error(E_WARNING, "%s() expects the argument (%s) to be a valid callback",
- get_active_function_name(TSRMLS_C), exception_handler_name?exception_handler_name:"unknown");
+ get_active_function_name(TSRMLS_C), exception_handler_name?exception_handler_name:"unknown");
efree(exception_handler_name);
return;
}
efree(exception_handler_name);
- }
- if (EG(user_exception_handler)) {
- had_orig_exception_handler = 1;
- *return_value = *EG(user_exception_handler);
- zval_copy_ctor(return_value);
- zend_ptr_stack_push(&EG(user_exception_handlers), EG(user_exception_handler));
- }
- ALLOC_ZVAL(EG(user_exception_handler));
+ if (EG(user_exception_handler)) {
+ had_orig_exception_handler = 1;
+ *return_value = *EG(user_exception_handler);
+ zval_copy_ctor(return_value);
+ zend_ptr_stack_push(&EG(user_exception_handlers), EG(user_exception_handler));
+ }
+
+ ALLOC_ZVAL(EG(user_exception_handler));
+ MAKE_COPY_ZVAL(&exception_handler, EG(user_exception_handler));
- if (Z_TYPE_P(exception_handler) == IS_NULL) { /* unset user-defined handler */
- FREE_ZVAL(EG(user_exception_handler));
+ if (!had_orig_exception_handler) {
+ RETURN_NULL();
+ }
+ } else {
+ if (EG(user_exception_handler)) {
+ zend_ptr_stack_push(&EG(user_exception_handlers), EG(user_exception_handler));
+ }
EG(user_exception_handler) = NULL;
RETURN_TRUE;
}
-
- MAKE_COPY_ZVAL(&exception_handler, EG(user_exception_handler));
-
- if (!had_orig_exception_handler) {
- RETURN_NULL();
- }
}
/* }}} */