diff --git a/library/alloc/src/io/cursor.rs b/library/alloc/src/io/cursor.rs index 21f6b8b5b3ffd..b1552e049a300 100644 --- a/library/alloc/src/io/cursor.rs +++ b/library/alloc/src/io/cursor.rs @@ -148,11 +148,13 @@ impl WriteThroughCursor for &mut Vec where A: Allocator, { + #[inline] fn write(this: &mut Cursor, buf: &[u8]) -> io::Result { let (pos, inner) = this.into_parts_mut(); vec_write_all(pos, inner, buf) } + #[inline] fn write_vectored(this: &mut Cursor, bufs: &[IoSlice<'_>]) -> io::Result { let (pos, inner) = this.into_parts_mut(); vec_write_all_vectored(pos, inner, bufs) @@ -163,12 +165,14 @@ where true } + #[inline] fn write_all(this: &mut Cursor, buf: &[u8]) -> io::Result<()> { let (pos, inner) = this.into_parts_mut(); vec_write_all(pos, inner, buf)?; Ok(()) } + #[inline] fn write_all_vectored(this: &mut Cursor, bufs: &mut [IoSlice<'_>]) -> io::Result<()> { let (pos, inner) = this.into_parts_mut(); vec_write_all_vectored(pos, inner, bufs)?; @@ -186,11 +190,13 @@ impl WriteThroughCursor for Vec where A: Allocator, { + #[inline] fn write(this: &mut Cursor, buf: &[u8]) -> io::Result { let (pos, inner) = this.into_parts_mut(); vec_write_all(pos, inner, buf) } + #[inline] fn write_vectored(this: &mut Cursor, bufs: &[IoSlice<'_>]) -> io::Result { let (pos, inner) = this.into_parts_mut(); vec_write_all_vectored(pos, inner, bufs) @@ -201,12 +207,14 @@ where true } + #[inline] fn write_all(this: &mut Cursor, buf: &[u8]) -> io::Result<()> { let (pos, inner) = this.into_parts_mut(); vec_write_all(pos, inner, buf)?; Ok(()) } + #[inline] fn write_all_vectored(this: &mut Cursor, bufs: &mut [IoSlice<'_>]) -> io::Result<()> { let (pos, inner) = this.into_parts_mut(); vec_write_all_vectored(pos, inner, bufs)?; diff --git a/library/core/src/io/cursor.rs b/library/core/src/io/cursor.rs index fe4def531a84a..950e7a61a1456 100644 --- a/library/core/src/io/cursor.rs +++ b/library/core/src/io/cursor.rs @@ -96,6 +96,7 @@ impl Cursor { /// # fn force_inference(_: &Cursor>) {} /// # force_inference(&buff); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_io_structs", since = "1.79.0")] pub const fn new(inner: T) -> Cursor { @@ -115,6 +116,7 @@ impl Cursor { /// /// let vec = buff.into_inner(); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn into_inner(self) -> T { self.inner @@ -133,6 +135,7 @@ impl Cursor { /// /// let reference = buff.get_ref(); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_io_structs", since = "1.79.0")] pub const fn get_ref(&self) -> &T { @@ -155,6 +158,7 @@ impl Cursor { /// /// let reference = buff.get_mut(); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_mut_cursor", since = "1.86.0")] pub const fn get_mut(&mut self) -> &mut T { @@ -180,6 +184,7 @@ impl Cursor { /// buff.seek(SeekFrom::Current(-1)).unwrap(); /// assert_eq!(buff.position(), 1); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_io_structs", since = "1.79.0")] pub const fn position(&self) -> u64 { @@ -203,6 +208,7 @@ impl Cursor { /// buff.set_position(4); /// assert_eq!(buff.position(), 4); /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_mut_cursor", since = "1.86.0")] pub const fn set_position(&mut self, pos: u64) { @@ -239,6 +245,7 @@ where /// buff.set_position(6); /// assert_eq!(buff.split(), ([1, 2, 3, 4, 5].as_slice(), [].as_slice())); /// ``` + #[inline] #[unstable(feature = "cursor_split", issue = "86369")] pub fn split(&self) -> (&[u8], &[u8]) { let slice = self.inner.as_ref(); @@ -270,6 +277,7 @@ where /// buff.set_position(6); /// assert_eq!(buff.split_mut(), ([1, 2, 3, 4, 5].as_mut_slice(), [].as_mut_slice())); /// ``` + #[inline] #[unstable(feature = "cursor_split", issue = "86369")] pub fn split_mut(&mut self) -> (&mut [u8], &mut [u8]) { let slice = self.inner.as_mut(); @@ -438,6 +446,7 @@ impl io::Seek for Cursor where T: AsRef<[u8]>, { + #[inline] fn seek(&mut self, style: SeekFrom) -> io::Result { let (base_pos, offset) = match style { SeekFrom::Start(n) => { @@ -459,10 +468,12 @@ where } } + #[inline] fn stream_len(&mut self) -> io::Result { Ok(self.get_ref().as_ref().len() as u64) } + #[inline] fn stream_position(&mut self) -> io::Result { Ok(self.position()) } diff --git a/library/core/src/io/size_hint.rs b/library/core/src/io/size_hint.rs index fa4e25c62f6d0..2c00891c2ee51 100644 --- a/library/core/src/io/size_hint.rs +++ b/library/core/src/io/size_hint.rs @@ -40,6 +40,7 @@ pub trait SizeHint { /// `(self.lower_bound(), self.upper_bound())`. /// /// Without specialization, types implementing this trait will return `(0, None)`. + #[inline] final fn size_hint(&self) -> (usize, Option) { (self.lower_bound(), self.upper_bound()) } diff --git a/library/core/src/io/write.rs b/library/core/src/io/write.rs index cdddd380885f4..253c4faf7df44 100644 --- a/library/core/src/io/write.rs +++ b/library/core/src/io/write.rs @@ -131,6 +131,7 @@ pub trait Write { /// ``` /// /// [`write`]: Write::write + #[inline] #[stable(feature = "iovec", since = "1.36.0")] fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result { default_write_vectored(|b| self.write(b), bufs) @@ -146,6 +147,7 @@ pub trait Write { /// The default implementation returns `false`. /// /// [`write_vectored`]: Write::write_vectored + #[inline] #[unstable(feature = "can_vector", issue = "69941")] fn is_write_vectored(&self) -> bool { false @@ -210,6 +212,7 @@ pub trait Write { /// Ok(()) /// } /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] fn write_all(&mut self, mut buf: &[u8]) -> Result<()> { while !buf.is_empty() { @@ -274,6 +277,7 @@ pub trait Write { /// assert_eq!(writer, &[1, 2, 3, 4, 5, 6]); /// # Ok(()) } /// ``` + #[inline] #[unstable(feature = "write_all_vectored", issue = "70436")] fn write_all_vectored(&mut self, mut bufs: &mut [IoSlice<'_>]) -> Result<()> { // Guarantee that bufs is empty if it contains no data, @@ -327,6 +331,7 @@ pub trait Write { /// Ok(()) /// } /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> Result<()> { if let Some(s) = args.as_statically_known_str() { @@ -357,6 +362,7 @@ pub trait Write { /// Ok(()) /// } /// ``` + #[inline] #[stable(feature = "rust1", since = "1.0.0")] fn by_ref(&mut self) -> &mut Self where @@ -368,6 +374,7 @@ pub trait Write { /// Default implementation of [`Write::write_vectored`], which is currently used /// in `libstd` for file system implementations of similar methods. +#[inline] #[doc(hidden)] #[unstable(feature = "core_io_internals", reason = "exposed only for libstd", issue = "none")] pub fn default_write_vectored(write: F, bufs: &[IoSlice<'_>]) -> Result