Skip to content

Commit

Permalink
optimize code, --filter=[unit]
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Sep 26, 2024
1 parent c26f064 commit 17a8a8f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
11 changes: 3 additions & 8 deletions ext-src/php_swoole_cxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -709,11 +709,11 @@ static inline void print_error(zend_object *exception, int severity) {
} // namespace zend

/* use void* to match some C callback function pointers */
static sw_inline void sw_callable_free(void *fci_cache) {
delete (zend::Callable *) fci_cache;
static inline void sw_callable_free(void *ptr) {
delete (zend::Callable *) ptr;
}

static zend::Callable *sw_callable_create(zval *zfn) {
static inline zend::Callable *sw_callable_create(zval *zfn) {
auto fn = new zend::Callable(zfn);
if (fn->ready()) {
return fn;
Expand All @@ -722,8 +722,3 @@ static zend::Callable *sw_callable_create(zval *zfn) {
return nullptr;
}
}

static inline void php_swoole_callable_free(void *ptr) {
zend::Callable *cb = (zend::Callable *) ptr;
delete cb;
}
10 changes: 5 additions & 5 deletions ext-src/swoole_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -543,13 +543,13 @@ static PHP_FUNCTION(swoole_event_set) {
auto writable_callback = sw_callable_create(zwritable_callback);
if (readable_callback) {
if (peo->readable_callback) {
swoole_event_defer(php_swoole_callable_free, peo->readable_callback);
swoole_event_defer(sw_callable_free, peo->readable_callback);
}
peo->readable_callback = readable_callback;
}
if (writable_callback) {
if (peo->writable_callback) {
swoole_event_defer(php_swoole_callable_free, peo->writable_callback);
swoole_event_defer(sw_callable_free, peo->writable_callback);
}
peo->writable_callback = writable_callback;
}
Expand Down Expand Up @@ -633,7 +633,7 @@ static PHP_FUNCTION(swoole_event_cycle) {
if (sw_reactor()->idle_task.callback == nullptr) {
RETURN_FALSE;
} else {
swoole_event_defer(php_swoole_callable_free, sw_reactor()->idle_task.data);
swoole_event_defer(sw_callable_free, sw_reactor()->idle_task.data);
sw_reactor()->idle_task.callback = nullptr;
sw_reactor()->idle_task.data = nullptr;
RETURN_TRUE;
Expand All @@ -642,14 +642,14 @@ static PHP_FUNCTION(swoole_event_cycle) {

if (!before) {
if (sw_reactor()->idle_task.data != nullptr) {
swoole_event_defer(php_swoole_callable_free, sw_reactor()->idle_task.data);
swoole_event_defer(sw_callable_free, sw_reactor()->idle_task.data);
}

sw_reactor()->idle_task.callback = event_end_callback;
sw_reactor()->idle_task.data = callback;
} else {
if (sw_reactor()->future_task.data != nullptr) {
swoole_event_defer(php_swoole_callable_free, sw_reactor()->future_task.data);
swoole_event_defer(sw_callable_free, sw_reactor()->future_task.data);
}

sw_reactor()->future_task.callback = event_end_callback;
Expand Down

0 comments on commit 17a8a8f

Please sign in to comment.