Skip to content

Commit

Permalink
Auto merge of #115542 - saethlin:fileencoder-is-bufwriter, r=WaffleLa…
Browse files Browse the repository at this point in the history
…pkin

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/rust#115298
Fixes rust-lang/rust#114671
Fixes rust-lang/rust#114045
Fixes rust-lang/rust#108100
Fixes rust-lang/rust#106787
  • Loading branch information
bors committed Sep 20, 2023
2 parents 79a4463 + 786233f commit 760e6ef
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit 760e6ef

Please sign in to comment.