Files
rust/library/alloc
Jonathan Brouwer 50e8d7e09e Rollup merge of #158083 - asder8215:default_read_to_end_mark_init, r=Darksonn
Fix perf regression in `Read::read_to_end` on short reads due to not checking if the cursor has initialized bytes

This PR fixes rust-lang/rust#158008.

In particular, in rust-lang/rust#150129, it refactored some code within `library/std/io/mod.rs` to utilize `BorrowedBuf::is_init` instead of manually checking `read_buf.init_len() == buf_len` to see if the read buffer had initialized bytes. However, the `BorrowedBuf` is never marked or set as init within this function, and I think this portion of the code:
```rust
 // SAFETY: These bytes were initialized but not filled in the previous loop
unsafe {
     read_buf.set_init(initialized);
}
```
was removed by mistake. This PR reverts the changes made by rust-lang/rust#150129, so that we can mark the `BorrowedBuf`/`read_buf` as initialized using `BorrowedBuf::set_init` if in a previous iteration the cursor has initialized bytes. This would allow `max_read_size` to not be marked as `usize::max` if the read buffer contains initialized bytes.

Closes: rust-lang/rust#142872
2026-08-11 11:14:52 +02:00
..