about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-10-20 15:42:24 -0700
committerAlex Crichton <alex@alexcrichton.com>2013-10-20 15:42:24 -0700
commitdf6225b8c3c981a686e5590dc59a7a5865476862 (patch)
treed33009f2ba3d901e4590fb001b722cb205d69df5 /src/libstd
parent69860b79b8f4882426fb5755c6d00e6717adeb38 (diff)
downloadrust-df6225b8c3c981a686e5590dc59a7a5865476862.tar.gz
rust-df6225b8c3c981a686e5590dc59a7a5865476862.zip
Don't allocate a string when calling println
Instead use format_args! to pass around a struct to pass along into std::fmt
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/rt/io/stdio.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/libstd/rt/io/stdio.rs b/src/libstd/rt/io/stdio.rs
index e3ca148862f..e6dd9a48099 100644
--- a/src/libstd/rt/io/stdio.rs
+++ b/src/libstd/rt/io/stdio.rs
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use fmt;
 use libc;
 use option::{Option, Some, None};
 use result::{Ok, Err};
@@ -56,7 +57,9 @@ pub fn stderr() -> StdWriter {
 pub fn print(s: &str) {
     // XXX: need to see if not caching stdin() is the cause of performance
     //      issues, it should be possible to cache a stdout handle in each Task
-    //      and then re-use that across calls to print/println
+    //      and then re-use that across calls to print/println. Note that the
+    //      resolution of this comment will affect all of the prints below as
+    //      well.
     stdout().write(s.as_bytes());
 }
 
@@ -68,6 +71,20 @@ pub fn println(s: &str) {
     out.write(['\n' as u8]);
 }
 
+/// Similar to `print`, but takes a `fmt::Arguments` structure to be compatible
+/// with the `format_args!` macro.
+pub fn print_args(fmt: &fmt::Arguments) {
+    let mut out = stdout();
+    fmt::write(&mut out as &mut Writer, fmt);
+}
+
+/// Similar to `println`, but takes a `fmt::Arguments` structure to be
+/// compatible with the `format_args!` macro.
+pub fn println_args(fmt: &fmt::Arguments) {
+    let mut out = stdout();
+    fmt::writeln(&mut out as &mut Writer, fmt);
+}
+
 /// Representation of a reader of a standard input stream
 pub struct StdReader {
     priv inner: ~RtioFileStream