From 80d733385aa2ff150a5d6f83ecfe55afc7e19e68 Mon Sep 17 00:00:00 2001 From: Jamey Sharp Date: Fri, 27 May 2016 19:34:20 -0700 Subject: [PATCH] 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. --- src/libstd/io/cursor.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index a1002fdb645..2d780559db1 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -230,6 +230,7 @@ impl BufRead for Cursor where T: AsRef<[u8]> { #[stable(feature = "rust1", since = "1.0.0")] impl<'a> Write for Cursor<&'a mut [u8]> { + #[inline] fn write(&mut self, data: &[u8]) -> io::Result { let pos = cmp::min(self.pos, self.inner.len() as u64); let amt = (&mut self.inner[(pos as usize)..]).write(data)?; @@ -269,6 +270,7 @@ impl Write for Cursor> { #[stable(feature = "cursor_box_slice", since = "1.5.0")] impl Write for Cursor> { + #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { let pos = cmp::min(self.pos, self.inner.len() as u64); let amt = (&mut self.inner[(pos as usize)..]).write(buf)?;