Rollup merge of #120053 - AldanTanneo:specialize-stdinlock-bytes, r=the8472
Specialize `Bytes` on `StdinLock<'_>` I noticed recently, while profiling a little project, that I was spending a lot of time reading from stdin (even with locking). I was using the `.bytes()` iterator adaptor; I figured, since `StdinLock` is a `BufReader` internally, it would work just as fast. But this is not the case, as `Bytes` is only specialized for the raw `BufReader`, and not the `StdinLock`/`MutexGuard` wrapper. Performance improved significantly when I wrapped the lock in a new `BufReader`, but I was still a bit sore about the double buffer indirection. This PR attempts to specialize it, by simply calling the already specialized implementation on `BufReader`.
This commit is contained in:
commit
cfa583b388
@ -8,7 +8,9 @@ use crate::io::prelude::*;
|
||||
use crate::cell::{Cell, RefCell};
|
||||
use crate::fmt;
|
||||
use crate::fs::File;
|
||||
use crate::io::{self, BorrowedCursor, BufReader, IoSlice, IoSliceMut, LineWriter, Lines};
|
||||
use crate::io::{
|
||||
self, BorrowedCursor, BufReader, IoSlice, IoSliceMut, LineWriter, Lines, SpecReadByte,
|
||||
};
|
||||
use crate::sync::atomic::{AtomicBool, Ordering};
|
||||
use crate::sync::{Arc, Mutex, MutexGuard, OnceLock, ReentrantMutex, ReentrantMutexGuard};
|
||||
use crate::sys::stdio;
|
||||
@ -483,6 +485,13 @@ impl Read for StdinLock<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl SpecReadByte for StdinLock<'_> {
|
||||
#[inline]
|
||||
fn spec_read_byte(&mut self) -> Option<io::Result<u8>> {
|
||||
BufReader::spec_read_byte(&mut *self.inner)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl BufRead for StdinLock<'_> {
|
||||
fn fill_buf(&mut self) -> io::Result<&[u8]> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user