-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std: Implement LineWriter::write_vectored
#67270
Conversation
This commit implements the `write_vectored` method of the `LineWriter` type. First discovered in bytecodealliance/wasmtime#629 the `write_vectored` method of `Stdout` bottoms out here but only ends up writing the first buffer due to the default implementation of `write_vectored`. Like `BufWriter`, however, `LineWriter` can have a non-default implementation of `write_vectored` which tries to preserve the vectored-ness as much as possible. Namely we can have a vectored write for everything before the newline and everything after the newline if all the stars align well. Also like `BufWriter`, though, special care is taken to ensure that whenever bytes are written we're sure to signal success since that represents a "commit" of writing bytes.
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
r? @sfackler |
self.need_flush = true; | ||
} | ||
if n == prefix_amt { | ||
match self.inner.write(&buf[..=j]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how I feel about one write_vectored call turning into up to write_vectored, write, flush, write, write_vectored
. Maybe it makes sense for LineWriter, but IIRC in general we tend to want to keep write/write_vectored relative 1:1 with downstream calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW LineWriter::write
is already a call to write
, flush
, then write
. We could skip a few calls here by creating a local Vec<IoSlice>
, but I figured that since it's all buffered here anyway a few more calls wouldn't matter too much.
The main thing is that we want to slice a &[IoSlice]
as if it were &[u8]
but we can't do that since we can't mutate IoSlice
in place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough.
@bors r+ |
📌 Commit 2fee28e has been approved by |
🌲 The tree is currently closed for pull requests below priority 100, this pull request will be tested once the tree is reopened |
…, r=sfackler std: Implement `LineWriter::write_vectored` This commit implements the `write_vectored` method of the `LineWriter` type. First discovered in bytecodealliance/wasmtime#629 the `write_vectored` method of `Stdout` bottoms out here but only ends up writing the first buffer due to the default implementation of `write_vectored`. Like `BufWriter`, however, `LineWriter` can have a non-default implementation of `write_vectored` which tries to preserve the vectored-ness as much as possible. Namely we can have a vectored write for everything before the newline and everything after the newline if all the stars align well. Also like `BufWriter`, though, special care is taken to ensure that whenever bytes are written we're sure to signal success since that represents a "commit" of writing bytes.
Rollup of 8 pull requests Successful merges: - #67189 (Unify binop wording) - #67270 (std: Implement `LineWriter::write_vectored`) - #67286 (Fix the configure.py TOML field for a couple LLVM options) - #67321 (make htons const fn) - #67382 (Remove some unnecessary `ATTR_*` constants.) - #67389 (Remove `SO_NOSIGPIPE` dummy variable on platforms that don't use it.) - #67394 (Remove outdated references to @t from comments) - #67406 (Suggest associated type when the specified one cannot be found) Failed merges: r? @ghost
This commit implements the
write_vectored
method of theLineWriter
type. First discovered in bytecodealliance/wasmtime#629 the
write_vectored
method ofStdout
bottoms out here but only ends upwriting the first buffer due to the default implementation of
write_vectored
.Like
BufWriter
, however,LineWriter
can have a non-defaultimplementation of
write_vectored
which tries to preserve thevectored-ness as much as possible. Namely we can have a vectored write
for everything before the newline and everything after the newline if
all the stars align well.
Also like
BufWriter
, though, special care is taken to ensure thatwhenever bytes are written we're sure to signal success since that
represents a "commit" of writing bytes.