Merge pull request #1896 from haileys/inline-never-for-rvo
Write to TaskStorage::future via never-inlined fn to encourage RVO
This commit is contained in:
commit
5a158b94bd
@ -73,9 +73,10 @@ mod thread {
|
|||||||
pub fn start(&'static mut self, init: impl FnOnce(Spawner)) {
|
pub fn start(&'static mut self, init: impl FnOnce(Spawner)) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let executor = &self.inner;
|
let executor = &self.inner;
|
||||||
self.ctx.closure.write(Closure::new(move |_| {
|
let future = Closure::new(move |_| {
|
||||||
executor.poll();
|
executor.poll();
|
||||||
}));
|
});
|
||||||
|
self.ctx.closure.write_in_place(|| future);
|
||||||
init(self.inner.spawner());
|
init(self.inner.spawner());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ impl<F: Future + 'static> AvailableTask<F> {
|
|||||||
fn initialize_impl<S>(self, future: impl FnOnce() -> F) -> SpawnToken<S> {
|
fn initialize_impl<S>(self, future: impl FnOnce() -> F) -> SpawnToken<S> {
|
||||||
unsafe {
|
unsafe {
|
||||||
self.task.raw.poll_fn.set(Some(TaskStorage::<F>::poll));
|
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);
|
let task = TaskRef::new(self.task);
|
||||||
|
|
||||||
|
@ -17,8 +17,9 @@ impl<T> UninitCell<T> {
|
|||||||
&mut *self.as_mut_ptr()
|
&mut *self.as_mut_ptr()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn write(&self, val: T) {
|
#[inline(never)]
|
||||||
ptr::write(self.as_mut_ptr(), val)
|
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) {
|
pub unsafe fn drop_in_place(&self) {
|
||||||
|
Loading…
Reference in New Issue
Block a user