You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Look at this simplication I found possible in the src/driver/read.rs
pub(crate)asyncfnread(self) -> BufResult<usize,T>{let complete = self.await;// Convert the operation result to `usize`let res = complete.result.map(|v| v asusize);// Recover the bufferletmut buf = complete.data.buf;// If the operation was successful, advance the initialized cursor.ifletOk(n) = res {// Safety: the kernel wrote `n` bytes to the buffer.unsafe{
buf.set_init(n);}}(res, buf)}/* old pub(crate) async fn read(mut self) -> BufResult<usize, T> { crate::future::poll_fn(move |cx| self.poll_i(cx)).await } fn poll_i(&mut self, cx: &mut Context<'_>) -> Poll<BufResult<usize, T>> { use std::future::Future; use std::pin::Pin; let complete = ready!(Pin::new(self).poll(cx)); // Convert the operation result to `usize` let res = complete.result.map(|v| v as usize); // Recover the buffer let mut buf = complete.data.buf; // If the operation was successful, advance the initialized cursor. if let Ok(n) = res { // Safety: the kernel wrote `n` bytes to the buffer. unsafe { buf.set_init(n); } } Poll::Ready((res, buf)) } */
It compiles and runs. Is fewer lines of code, one function instead of three, probably less cpu and less stack. Maybe less heap.
Any other driver operations that followed the earlier model might be easily swapped for this too.
Is anything important being lost with this?
The text was updated successfully, but these errors were encountered:
Yeah the completion trait was meant to also allow this sort of work. I had actually meant to do this not long after I introduced that PR, but didn't get around to it.
Look at this simplication I found possible in the src/driver/read.rs
It compiles and runs. Is fewer lines of code, one function instead of three, probably less cpu and less stack. Maybe less heap.
Any other driver operations that followed the earlier model might be easily swapped for this too.
Is anything important being lost with this?
The text was updated successfully, but these errors were encountered: