-
Notifications
You must be signed in to change notification settings - Fork 13.4k
core and std: Optimize write*!() and print*!() for a single argument #22335
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
r? @huonw (rust_highfive has picked a reviewer for you, use r? to override) |
@bors r+ bc7dd057 rollup |
@bors r- Ugh. This is actually a breaking change. Doing |
Turns out |
|
@pczarn: Unfortunately then |
c6ad5eb
to
a3e5cb3
Compare
/// | ||
/// ``` | ||
#[macro_export] | ||
macro_rules! format_arg { ($fmt:expr) => ({ |
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 suspect the two cases need to be in the same macro definition to be rendered,
macro_rules! format_args {
($fmt: expr) => ({ /* compiler built-in */ });
($fmt: expr, $($args: tt)*) => ({ /* compiler built-in */ });
}
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.
@erickt pointed out my mistake on IRC (interpreted this just a variation of format_args
rather than a new format_arg
macro).
In any case, I think the doc string for this needs updating, since AFAICT, it doesn't return Arguments
any more.
Before this patch, `write!(wr, "foo")` was not as fast as `wr.write_str("foo")` because the underlying write_fmt has some overhead in order to work with multiple arguments.
@huonw: I also have a branch that merges |
If this is adding a new |
#[stable(feature = "rust1", since = "1.0.0")] | ||
macro_rules! format { | ||
($fmt:expr) => { | ||
format_arg!($fmt).to_string() |
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.
How is this different from format_args!($fmt, $($arg)*).to_string()
?
@erickt: you can add a method for extracting the only string piece out of |
@pczarn: doing that would be doing roughly the same amount of work |
Before this patch,
write!(wr, "foo")
was not as fast aswr.write_all("foo".as_bytes())
because the underlying write_fmt has some overhead in order to work with multiple arguments. This PR speeds that up by optimizing this specific case.