diff options
| author | kennytm <kennytm@gmail.com> | 2019-02-20 01:13:25 +0800 |
|---|---|---|
| committer | kennytm <kennytm@gmail.com> | 2019-02-20 11:58:42 +0800 |
| commit | 7ef11d4f849004e36a61949cfd01cc1a46fac75a (patch) | |
| tree | 60f2a0a8d0deb66f89f68a4b93a1fc4a8e11668f /src/libstd | |
| parent | e95297ca15d00363cafe2f56159898b7fa2e9e21 (diff) | |
| parent | 564c569bcb1b85ec3b1f93de60b7f7b385c5bd17 (diff) | |
| download | rust-7ef11d4f849004e36a61949cfd01cc1a46fac75a.tar.gz rust-7ef11d4f849004e36a61949cfd01cc1a46fac75a.zip | |
Rollup merge of #58530 - scottmcm:monomorphize-less, r=TimNN
Monomorphize less code in fs::{read|write}
Since the generic-ness is only for the as_refs, might as well have std just compile the important part once instead of on every use.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/fs.rs | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index f1e8619fc8f..def51c79a85 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -254,10 +254,13 @@ fn initial_buffer_size(file: &File) -> usize { /// ``` #[stable(feature = "fs_read_write_bytes", since = "1.26.0")] pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> { - let mut file = File::open(path)?; - let mut bytes = Vec::with_capacity(initial_buffer_size(&file)); - file.read_to_end(&mut bytes)?; - Ok(bytes) + fn inner(path: &Path) -> io::Result<Vec<u8>> { + let mut file = File::open(path)?; + let mut bytes = Vec::with_capacity(initial_buffer_size(&file)); + file.read_to_end(&mut bytes)?; + Ok(bytes) + } + inner(path.as_ref()) } /// Read the entire contents of a file into a string. @@ -296,10 +299,13 @@ pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> { /// ``` #[stable(feature = "fs_read_write", since = "1.26.0")] pub fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> { - let mut file = File::open(path)?; - let mut string = String::with_capacity(initial_buffer_size(&file)); - file.read_to_string(&mut string)?; - Ok(string) + fn inner(path: &Path) -> io::Result<String> { + let mut file = File::open(path)?; + let mut string = String::with_capacity(initial_buffer_size(&file)); + file.read_to_string(&mut string)?; + Ok(string) + } + inner(path.as_ref()) } /// Write a slice as the entire contents of a file. @@ -326,7 +332,10 @@ pub fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> { /// ``` #[stable(feature = "fs_read_write_bytes", since = "1.26.0")] pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result<()> { - File::create(path)?.write_all(contents.as_ref()) + fn inner(path: &Path, contents: &[u8]) -> io::Result<()> { + File::create(path)?.write_all(contents) + } + inner(path.as_ref(), contents.as_ref()) } impl File { |
