about summary refs log tree commit diff
path: root/src/libextra
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-06-30 09:32:01 -0700
committerbors <bors@rust-lang.org>2013-06-30 09:32:01 -0700
commit179040033545beac0e8f4aea8bbbf2e08469dc7a (patch)
treec7fe8365b82802cb8c634500f6444896014e0286 /src/libextra
parent2b3569a1b39097481877cf8fee538c78099c5acd (diff)
parentd3155faedee97cb916735573fbf067d6305ee730 (diff)
auto merge of #7465 : alexcrichton/rust/issue-4432, r=cmr
This stems from trying to perform as few allocations as possible throughout the standard libraries.

This specializes the `ToStr` implementation for floats/ints separately because it's known that ints will have a maximum length (whereas floats could be very very large).

I also removed a `FIXME` to remove a malloc from the `to_str()` of floats in `repr.rs` because I think that this should be addressed elsewhere. I think that we may not be able to avoid it easily because floats can have such large representations, but regardless this should be a problem with the implementation of `float_to_str_bytes_common` now and not in the `Repr` module.
Diffstat (limited to 'src/libextra')
-rw-r--r--src/libextra/terminfo/parm.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/libextra/terminfo/parm.rs b/src/libextra/terminfo/parm.rs
index f3edd81f9ac..b7d21ea0ee3 100644
--- a/src/libextra/terminfo/parm.rs
+++ b/src/libextra/terminfo/parm.rs
@@ -11,7 +11,7 @@
 //! Parameterized string expansion
 
 use std::{char, vec, util};
-use std::num::strconv::{SignNone,SignNeg,SignAll,DigAll,to_str_bytes_common};
+use std::num::strconv::{SignNone,SignNeg,SignAll,int_to_str_bytes_common};
 use std::iterator::IteratorUtil;
 
 #[deriving(Eq)]
@@ -469,14 +469,20 @@ priv fn format(val: Param, op: FormatOp, flags: Flags) -> Result<~[u8],~str> {
                         FormatHex|FormatHEX => 16,
                         FormatString => util::unreachable()
                     };
-                    let (s,_) = match op {
+                    let mut s = ~[];
+                    match op {
                         FormatDigit => {
                             let sign = if flags.sign { SignAll } else { SignNeg };
-                            to_str_bytes_common(&d, radix, false, sign, DigAll)
+                            do int_to_str_bytes_common(d, radix, sign) |c| {
+                                s.push(c);
+                            }
+                        }
+                        _ => {
+                            do int_to_str_bytes_common(d as uint, radix, SignNone) |c| {
+                                s.push(c);
+                            }
                         }
-                        _ => to_str_bytes_common(&(d as uint), radix, false, SignNone, DigAll)
                     };
-                    let mut s = s;
                     if flags.precision > s.len() {
                         let mut s_ = vec::with_capacity(flags.precision);
                         let n = flags.precision - s.len();