Skip to content

Commit a9d049e

Browse files
committed
Auto merge of rust-lang#115542 - saethlin:fileencoder-is-bufwriter, r=WaffleLapkin
Simplify/Optimize FileEncoder FileEncoder is basically a BufWriter except that it exposes access to the not-written-to-yet region of the buffer so that some users can write directly to the buffer. This strategy is awesome because it lets us avoid calling memcpy for small copies, but the previous strategy was based on the writer accessing a `&mut [MaybeUninit<u8>; N]` and returning a `&[u8]` which is an API which currently mandates the use of unsafe code, making that interface in general not that appealing. So this PR cleans up the FileEncoder implementation and builds on that general idea of direct buffer access in order to prevent `memcpy` calls in a few key places when encoding the dep graph and rmeta tables. The interface used here is now 100% safe, but with the caveat that internally we need to avoid trusting the number of bytes that the provided function claims to have written. The original primary objective of this PR was to clean up the FileEncoder implementation so that the fix for the following issues would be easy to implement. The fix for these issues is to correctly update self.buffered even when writes fail, which I think it's easy to verify manually is now done, because all the FileEncoder methods are small. Fixes rust-lang#115298 Fixes rust-lang#114671 Fixes rust-lang#114045 Fixes rust-lang#108100 Fixes rust-lang#106787
2 parents ad5ec48 + 3bd032e commit a9d049e

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

std/src/io/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ impl Error {
511511
/// let eof_error = Error::from(ErrorKind::UnexpectedEof);
512512
/// ```
513513
#[stable(feature = "rust1", since = "1.0.0")]
514+
#[inline(never)]
514515
pub fn new<E>(kind: ErrorKind, error: E) -> Error
515516
where
516517
E: Into<Box<dyn error::Error + Send + Sync>>,

0 commit comments

Comments
 (0)