Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline some Cursor calls for slices #60656

Merged
merged 1 commit into from
May 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/libstd/io/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,15 @@ impl<T> BufRead for Cursor<T> where T: AsRef<[u8]> {
}

// Non-resizing write implementation
#[inline]
fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result<usize> {
let pos = cmp::min(*pos_mut, slice.len() as u64);
let amt = (&mut slice[(pos as usize)..]).write(buf)?;
*pos_mut += amt as u64;
Ok(amt)
}

#[inline]
fn slice_write_vectored(
pos_mut: &mut u64,
slice: &mut [u8],
Expand Down Expand Up @@ -341,6 +343,7 @@ impl Write for Cursor<&mut [u8]> {
slice_write_vectored(&mut self.pos, self.inner, bufs)
}

#[inline]
fn flush(&mut self) -> io::Result<()> { Ok(()) }
}

Expand All @@ -354,6 +357,7 @@ impl Write for Cursor<&mut Vec<u8>> {
vec_write_vectored(&mut self.pos, self.inner, bufs)
}

#[inline]
fn flush(&mut self) -> io::Result<()> { Ok(()) }
}

Expand All @@ -367,6 +371,7 @@ impl Write for Cursor<Vec<u8>> {
vec_write_vectored(&mut self.pos, &mut self.inner, bufs)
}

#[inline]
fn flush(&mut self) -> io::Result<()> { Ok(()) }
}

Expand All @@ -382,6 +387,7 @@ impl Write for Cursor<Box<[u8]>> {
slice_write_vectored(&mut self.pos, &mut self.inner, bufs)
}

#[inline]
fn flush(&mut self) -> io::Result<()> { Ok(()) }
}

Expand Down