From f74ae92859cec48bad63f4d70c4538edb5555166 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Thu, 4 Mar 2021 18:48:39 +0800 Subject: [PATCH] use c native char * --- yaf_dispatcher.c | 12 ++++-------- yaf_request.c | 22 ++++++++++++++++++++++ yaf_request.h | 2 ++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/yaf_dispatcher.c b/yaf_dispatcher.c index 3dfd374b..cc522d26 100644 --- a/yaf_dispatcher.c +++ b/yaf_dispatcher.c @@ -687,7 +687,7 @@ static ZEND_HOT int yaf_dispatcher_handle(yaf_dispatcher_object *dispatcher) /* /* }}} */ static ZEND_COLD zend_never_inline void yaf_dispatcher_exception_handler(yaf_dispatcher_object *dispatcher) /* {{{ */ { - zend_string *exception_str, *controller, *action; + zend_string *controller, *action; zval exception; const zend_op *opline; yaf_request_object *request = Z_YAFREQUESTOBJ(dispatcher->request); @@ -724,12 +724,10 @@ static ZEND_COLD zend_never_inline void yaf_dispatcher_exception_handler(yaf_dis zend_string_release(action); /** use $request->getException() instand of */ - exception_str = zend_string_init(ZEND_STRL("exception"), 0); - if (yaf_request_set_params_single(request, exception_str, &exception)) { + if (yaf_request_set_str_params_single(request, "exception", sizeof("exception") - 1, &exception)) { zval_ptr_dtor(&exception); } else { /* failover to uncaught exception */ - zend_string_release(exception_str); EG(exception) = Z_OBJ(exception); YAF_DISPATCHER_FLAGS(dispatcher) = ~YAF_DISPATCHER_IN_EXCEPTION; return; @@ -737,8 +735,7 @@ static ZEND_COLD zend_never_inline void yaf_dispatcher_exception_handler(yaf_dis yaf_request_set_dispatched(request, 0); if (UNEXPECTED(!yaf_dispatcher_init_view(dispatcher, NULL, NULL))) { - yaf_request_del_param(request, exception_str); - zend_string_release(exception_str); + yaf_request_del_str_param(request, "exception", sizeof("exception") - 1); YAF_DISPATCHER_FLAGS(dispatcher) = ~YAF_DISPATCHER_IN_EXCEPTION; return; } @@ -755,8 +752,7 @@ static ZEND_COLD zend_never_inline void yaf_dispatcher_exception_handler(yaf_dis } } - yaf_request_del_param(request, exception_str); - zend_string_release(exception_str); + yaf_request_del_str_param(request, "exception", sizeof("exception") - 1); if (!(YAF_DISPATCHER_FLAGS(dispatcher) & YAF_DISPATCHER_RETURN_RESPONSE)) { yaf_response_response(Z_YAFRESPONSEOBJ(dispatcher->response)); diff --git a/yaf_request.c b/yaf_request.c index 7d8a0e73..332d0c05 100644 --- a/yaf_request.c +++ b/yaf_request.c @@ -737,6 +737,14 @@ ZEND_HOT zval *yaf_request_query(unsigned type, zend_string *name) /* {{{ */ { } /* }}} */ +int yaf_request_del_str_param(yaf_request_object *request, const char *key, size_t len) /* {{{ */ { + if (request->params) { + return zend_hash_str_del(request->params, key, len); + } + return 0; +} +/* }}} */ + int yaf_request_del_param(yaf_request_object *request, zend_string *key) /* {{{ */ { if (request->params) { return zend_hash_del(request->params, key); @@ -745,6 +753,20 @@ int yaf_request_del_param(yaf_request_object *request, zend_string *key) /* {{{ } /* }}} */ +int yaf_request_set_str_params_single(yaf_request_object *request, const char *key, size_t len, zval *value) /* {{{ */ { + if (!request->params) { + ALLOC_HASHTABLE(request->params); + zend_hash_init(request->params, 8, NULL, ZVAL_PTR_DTOR, 0); + YAF_ALLOW_VIOLATION(request->params); + } + if ((zend_hash_str_update(request->params, key, len, value)) != NULL) { + Z_TRY_ADDREF_P(value); + return 1; + } + return 0; +} +/* }}} */ + int yaf_request_set_params_single(yaf_request_object *request, zend_string *key, zval *value) /* {{{ */ { if (!request->params) { ALLOC_HASHTABLE(request->params); diff --git a/yaf_request.h b/yaf_request.h index 4c8926fd..de9ecbc3 100644 --- a/yaf_request.h +++ b/yaf_request.h @@ -66,7 +66,9 @@ zend_string *yaf_request_get_language(yaf_request_object *request); void yaf_request_set_mvc(yaf_request_object *request, zend_string *module, zend_string *controller, zend_string *action, zend_array *params); int yaf_request_set_params_single(yaf_request_object *instance, zend_string *key, zval *value); +int yaf_request_set_str_params_single(yaf_request_object *instance, const char *key, size_t len, zval *value); int yaf_request_set_params_multi(yaf_request_object *instance, zval *values); +int yaf_request_del_str_param(yaf_request_object *request, const char *key, size_t len); int yaf_request_del_param(yaf_request_object *request, zend_string *key); const char *yaf_request_strip_base_uri(zend_string *uri, zend_string *base_uri, size_t *len); const char *yaf_request_get_request_method(void);