Skip to content

Commit 80d7333

Browse files
committed
Inline simple Cursor write calls
Implementing the Write trait for Cursors over slices is so light-weight that under some circumstances multiple writes can be fused into a single instruction. In general I think inlining these functions is a good idea because most of the code can be constant-folded and copy-propagated away. Closes issue #33916.
1 parent 7bddce6 commit 80d7333

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/libstd/io/cursor.rs

+2
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ impl<T> BufRead for Cursor<T> where T: AsRef<[u8]> {
230230

231231
#[stable(feature = "rust1", since = "1.0.0")]
232232
impl<'a> Write for Cursor<&'a mut [u8]> {
233+
#[inline]
233234
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
234235
let pos = cmp::min(self.pos, self.inner.len() as u64);
235236
let amt = (&mut self.inner[(pos as usize)..]).write(data)?;
@@ -269,6 +270,7 @@ impl Write for Cursor<Vec<u8>> {
269270

270271
#[stable(feature = "cursor_box_slice", since = "1.5.0")]
271272
impl Write for Cursor<Box<[u8]>> {
273+
#[inline]
272274
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
273275
let pos = cmp::min(self.pos, self.inner.len() as u64);
274276
let amt = (&mut self.inner[(pos as usize)..]).write(buf)?;

0 commit comments

Comments
 (0)