Auto merge of #130803 - cuviper:file-buffered, r=joshtriplett

Add `File` constructors that return files wrapped with a buffer

In addition to the light convenience, these are intended to raise visibility that buffering is something you should consider when opening a file, since unbuffered I/O is a common performance footgun to Rust newcomers.

ACP: https://github.com/rust-lang/libs-team/issues/446
Tracking Issue: #130804
This commit is contained in:
bors 2024-09-25 04:57:12 +00:00
commit 4c62024cd5
33 changed files with 151 additions and 41 deletions

View file

@ -517,7 +517,7 @@ mod cgroups {
use crate::borrow::Cow;
use crate::ffi::OsString;
use crate::fs::{File, exists};
use crate::io::{BufRead, BufReader, Read};
use crate::io::{BufRead, Read};
use crate::os::unix::ffi::OsStringExt;
use crate::path::{Path, PathBuf};
use crate::str::from_utf8;
@ -690,7 +690,7 @@ mod cgroups {
/// If the cgroupfs is a bind mount then `group_path` is adjusted to skip
/// over the already-included prefix
fn find_mountpoint(group_path: &Path) -> Option<(Cow<'static, str>, &Path)> {
let mut reader = BufReader::new(File::open("/proc/self/mountinfo").ok()?);
let mut reader = File::open_buffered("/proc/self/mountinfo").ok()?;
let mut line = String::with_capacity(256);
loop {
line.clear();