From c518f2dd7040eca7591d3cacffe3646d8f54ac7c Mon Sep 17 00:00:00 2001 From: Lukas Kalbertodt Date: Thu, 14 Mar 2019 13:27:49 +0100 Subject: Overwrite Cursor's `Seek::stream_{len, position}` for performance --- src/libstd/io/cursor.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/libstd') diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index 873da0898c7..247d45c3ec9 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -212,6 +212,14 @@ impl io::Seek for Cursor where T: AsRef<[u8]> { "invalid seek to a negative or overflowing position")) } } + + fn stream_len(&mut self) -> io::Result { + Ok(self.inner.as_ref().len() as u64) + } + + fn stream_position(&mut self) -> io::Result { + Ok(self.pos) + } } #[stable(feature = "rust1", since = "1.0.0")] -- cgit 1.4.1-3-g733a5