about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorMatt Brubeck <mbrubeck@limpet.net>2018-04-02 09:10:44 -0700
committerMatt Brubeck <mbrubeck@limpet.net>2018-04-02 09:33:27 -0700
commit85310860c25c8525c03b2ffe12674c1914917aa0 (patch)
treec92eedbd668eacf5ab68e5c04f77ccf7d587ee9b /src/libstd
parent097efa9a998d4f3a4aee3af126e8f8a9eba1ae07 (diff)
downloadrust-85310860c25c8525c03b2ffe12674c1914917aa0.tar.gz
rust-85310860c25c8525c03b2ffe12674c1914917aa0.zip
Add performance note to fs::read docs
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/fs.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs
index 479e4d08f4b..7bd1adc411a 100644
--- a/src/libstd/fs.rs
+++ b/src/libstd/fs.rs
@@ -231,7 +231,9 @@ fn initial_buffer_size(file: &File) -> usize {
 /// Read the entire contents of a file into a bytes vector.
 ///
 /// This is a convenience function for using [`File::open`] and [`read_to_end`]
-/// with fewer imports and without an intermediate variable.
+/// with fewer imports and without an intermediate variable.  It pre-allocates a
+/// buffer based on the file size when available, so it is generally faster than
+/// reading into a vector created with `Vec::new()`.
 ///
 /// [`File::open`]: struct.File.html#method.open
 /// [`read_to_end`]: ../io/trait.Read.html#method.read_to_end
@@ -270,7 +272,9 @@ pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
 /// Read the entire contents of a file into a string.
 ///
 /// This is a convenience function for using [`File::open`] and [`read_to_string`]
-/// with fewer imports and without an intermediate variable.
+/// with fewer imports and without an intermediate variable.  It pre-allocates a
+/// buffer based on the file size when available, so it is generally faster than
+/// reading into a string created with `String::new()`.
 ///
 /// [`File::open`]: struct.File.html#method.open
 /// [`read_to_string`]: ../io/trait.Read.html#method.read_to_string