Merge pull request #45 from Brooooooklyn/executor-prune

chore: remove useless Box in Task
This commit is contained in:
LongYinan 2020-05-11 18:41:20 +08:00 committed by GitHub
commit a5a1d76ad3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -58,11 +58,11 @@ pub fn execute<F: 'static + Future<Output = ()>>(
&UV_ASYNC_V_TABLE, &UV_ASYNC_V_TABLE,
)); ));
let context = Context::from_waker(&waker); let context = Context::from_waker(&waker);
let mut task = Box::new(Task { let mut task = Task {
future: Box::pin(future), future: Box::pin(future),
context, context,
}); };
if !task.as_mut().poll_future() { if !task.poll_future() {
let arc_task = Arc::new(task); let arc_task = Arc::new(task);
sys::uv_handle_set_data( sys::uv_handle_set_data(
uv_async_t_ref as *mut _ as *mut sys::uv_handle_t, uv_async_t_ref as *mut _ as *mut sys::uv_handle_t,
@ -83,7 +83,7 @@ impl<'a> Task<'a> {
} }
unsafe extern "C" fn poll_future(handle: *mut sys::uv_async_t) { unsafe extern "C" fn poll_future(handle: *mut sys::uv_async_t) {
let data_ptr = sys::uv_handle_get_data(handle as *mut sys::uv_handle_t) as *mut Box<Task>; let data_ptr = sys::uv_handle_get_data(handle as *mut sys::uv_handle_t) as *mut Task;
let mut task = Arc::from_raw(data_ptr); let mut task = Arc::from_raw(data_ptr);
if let Some(mut_task) = Arc::get_mut(&mut task) { if let Some(mut_task) = Arc::get_mut(&mut task) {
if mut_task.poll_future() { if mut_task.poll_future() {