Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
/// Reads 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, without an intermediate variable, and with improved performance
/// by referencing the file's metadata to preallocate buffer size.
Comment on lines 273 to +275
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still game to accept this but it's a "should have better performance" or "may be faster and more efficient" rather than "is definitely going to have better performance for (specific implementation detail)" because of OS-specific differences.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, which part are you referring to by saying "may be faster and more efficient"?

Cf. #130600 (comment)

The only optimization that fs::read_to_string has is that it can use the size from the file metadata directly and doesn't need to retrieve the current seek position of the file handle.

///
/// [`read_to_string`]: Read::read_to_string
///
Expand Down
Loading