Skip to content

Commit 04ac697

Browse files
committed
auto merge of #9979 : alexcrichton/rust/print-no-alloc, r=huonw
Instead use format_args! to pass around a struct to pass along into std::fmt
2 parents cd59a7c + df6225b commit 04ac697

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/libstd/rt/io/stdio.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use fmt;
1112
use libc;
1213
use option::{Option, Some, None};
1314
use result::{Ok, Err};
@@ -56,7 +57,9 @@ pub fn stderr() -> StdWriter {
5657
pub fn print(s: &str) {
5758
// XXX: need to see if not caching stdin() is the cause of performance
5859
// issues, it should be possible to cache a stdout handle in each Task
59-
// and then re-use that across calls to print/println
60+
// and then re-use that across calls to print/println. Note that the
61+
// resolution of this comment will affect all of the prints below as
62+
// well.
6063
stdout().write(s.as_bytes());
6164
}
6265

@@ -68,6 +71,20 @@ pub fn println(s: &str) {
6871
out.write(['\n' as u8]);
6972
}
7073

74+
/// Similar to `print`, but takes a `fmt::Arguments` structure to be compatible
75+
/// with the `format_args!` macro.
76+
pub fn print_args(fmt: &fmt::Arguments) {
77+
let mut out = stdout();
78+
fmt::write(&mut out as &mut Writer, fmt);
79+
}
80+
81+
/// Similar to `println`, but takes a `fmt::Arguments` structure to be
82+
/// compatible with the `format_args!` macro.
83+
pub fn println_args(fmt: &fmt::Arguments) {
84+
let mut out = stdout();
85+
fmt::writeln(&mut out as &mut Writer, fmt);
86+
}
87+
7188
/// Representation of a reader of a standard input stream
7289
pub struct StdReader {
7390
priv inner: ~RtioFileStream

src/libsyntax/ext/expand.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -999,16 +999,11 @@ pub fn std_macros() -> @str {
999999
macro_rules! writeln(($dst:expr, $($arg:tt)*) => (
10001000
format_args!(|args| { ::std::fmt::writeln($dst, args) }, $($arg)*)
10011001
))
1002-
// FIXME(#6846) once stdio is redesigned, this shouldn't perform an
1003-
// allocation but should rather delegate to an invocation of
1004-
// write! instead of format!
10051002
macro_rules! print (
1006-
($($arg:tt)*) => (::std::io::print(format!($($arg)*)))
1003+
($($arg:tt)*) => (format_args!(::std::rt::io::stdio::print_args, $($arg)*))
10071004
)
1008-
// FIXME(#6846) once stdio is redesigned, this shouldn't perform an
1009-
// allocation but should rather delegate to an io::Writer
10101005
macro_rules! println (
1011-
($($arg:tt)*) => (::std::io::println(format!($($arg)*)))
1006+
($($arg:tt)*) => (format_args!(::std::rt::io::stdio::println_args, $($arg)*))
10121007
)
10131008

10141009
macro_rules! local_data_key (

0 commit comments

Comments
 (0)