Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upcore and std: Optimize write*!() and print*!() for a single argument #22335
Conversation
rust-highfive
assigned
huonw
Feb 14, 2015
This comment has been minimized.
This comment has been minimized.
|
r? @huonw (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@bors r- Ugh. This is actually a breaking change. Doing |
This comment has been minimized.
This comment has been minimized.
|
Turns out |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@pczarn: Unfortunately then |
erickt
force-pushed the
erickt:single-write
branch
2 times, most recently
from
c6ad5eb
to
a3e5cb3
Feb 16, 2015
huonw
reviewed
Feb 16, 2015
| /// | ||
| /// ``` | ||
| #[macro_export] | ||
| macro_rules! format_arg { ($fmt:expr) => ({ |
This comment has been minimized.
This comment has been minimized.
huonw
Feb 16, 2015
Member
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 */ });
}
This comment has been minimized.
This comment has been minimized.
huonw
Feb 16, 2015
Member
@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.
erickt
force-pushed the
erickt:single-write
branch
from
a3e5cb3
to
d69728b
Feb 16, 2015
erickt
force-pushed the
erickt:single-write
branch
from
d69728b
to
ee7ab9a
Feb 16, 2015
This comment has been minimized.
This comment has been minimized.
|
@huonw: I also have a branch that merges |
This comment has been minimized.
This comment has been minimized.
|
If this is adding a new |
pczarn
reviewed
Feb 16, 2015
| #[stable(feature = "rust1", since = "1.0.0")] | ||
| macro_rules! format { | ||
| ($fmt:expr) => { | ||
| format_arg!($fmt).to_string() |
This comment has been minimized.
This comment has been minimized.
pczarn
Feb 16, 2015
Contributor
How is this different from format_args!($fmt, $($arg)*).to_string()?
This comment has been minimized.
This comment has been minimized.
|
@erickt: you can add a method for extracting the only string piece out of |
This comment has been minimized.
This comment has been minimized.
|
@pczarn: doing that would be doing roughly the same amount of work |
erickt commentedFeb 14, 2015
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.