Rollup merge of #139069 - a1phyr:better_take, r=joboet
`io::Take`: avoid new `BorrowedBuf` creation in some case If `self.limit == buf.capacity()`, doing the whole `BorrowedBuf` dance is not necessary.
This commit is contained in:
commit
7c0a14f030
1 changed files with 4 additions and 4 deletions
|
@ -2989,11 +2989,11 @@ impl<T: Read> Read for Take<T> {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
if self.limit <= buf.capacity() as u64 {
|
||||
// if we just use an as cast to convert, limit may wrap around on a 32 bit target
|
||||
let limit = cmp::min(self.limit, usize::MAX as u64) as usize;
|
||||
if self.limit < buf.capacity() as u64 {
|
||||
// The condition above guarantees that `self.limit` fits in `usize`.
|
||||
let limit = self.limit as usize;
|
||||
|
||||
let extra_init = cmp::min(limit as usize, buf.init_ref().len());
|
||||
let extra_init = cmp::min(limit, buf.init_ref().len());
|
||||
|
||||
// SAFETY: no uninit data is written to ibuf
|
||||
let ibuf = unsafe { &mut buf.as_mut()[..limit] };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue