write to TaskStorage::future via inline(never) fn to encourage RVO

This commit is contained in:
Hailey Somerville 2023-09-14 13:03:38 +10:00
parent 5e381d49da
commit 3a1ed823f8
2 changed files with 4 additions and 3 deletions

View File

@ -203,7 +203,7 @@ impl<F: Future + 'static> AvailableTask<F> {
fn initialize_impl<S>(self, future: impl FnOnce() -> F) -> SpawnToken<S> {
unsafe {
self.task.raw.poll_fn.set(Some(TaskStorage::<F>::poll));
self.task.future.write(future());
self.task.future.write_in_place(future);
let task = TaskRef::new(self.task);

View File

@ -17,8 +17,9 @@ impl<T> UninitCell<T> {
&mut *self.as_mut_ptr()
}
pub unsafe fn write(&self, val: T) {
ptr::write(self.as_mut_ptr(), val)
#[inline(never)]
pub unsafe fn write_in_place(&self, func: impl FnOnce() -> T) {
ptr::write(self.as_mut_ptr(), func())
}
pub unsafe fn drop_in_place(&self) {