Skip to content

Commit 7e04e2c

Browse files
committed
---
yaml --- r: 151749 b: refs/heads/try2 c: c365252 h: refs/heads/master i: 151747: 1b70e88 v: v3
1 parent 59d7dfa commit 7e04e2c

File tree

15 files changed

+30
-46
lines changed

15 files changed

+30
-46
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: bcab97a32eca0bec431ff3d1065f07e10c600d80
8+
refs/heads/try2: c36525200240b1fae7e6871790b60aec856c2147
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ pub use core::fmt::{Show, Bool, Char, Signed, Unsigned, Octal, Binary};
500500
pub use core::fmt::{LowerHex, UpperHex, String, Pointer};
501501
pub use core::fmt::{Float, LowerExp, UpperExp};
502502
pub use core::fmt::{FormatError, WriteError};
503-
pub use core::fmt::{Argument, Arguments, write};
503+
pub use core::fmt::{Argument, Arguments, write, radix, Radix, RadixFmt};
504504

505505
#[doc(hidden)]
506506
pub use core::fmt::{argument, argumentstr, argumentuint};

branches/try2/src/libstd/num/i16.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use num::{ToStrRadix, FromStrRadix};
1515
use num::strconv;
1616
use option::Option;
1717
use slice::ImmutableVector;
18-
use str;
1918

2019
pub use core::i16::{BITS, BYTES, MIN, MAX};
2120

branches/try2/src/libstd/num/i32.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use num::{ToStrRadix, FromStrRadix};
1515
use num::strconv;
1616
use option::Option;
1717
use slice::ImmutableVector;
18-
use str;
1918

2019
pub use core::i32::{BITS, BYTES, MIN, MAX};
2120

branches/try2/src/libstd/num/i64.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use num::{ToStrRadix, FromStrRadix};
1515
use num::strconv;
1616
use option::Option;
1717
use slice::ImmutableVector;
18-
use str;
1918

2019
pub use core::i64::{BITS, BYTES, MIN, MAX};
2120

branches/try2/src/libstd/num/i8.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use num::{ToStrRadix, FromStrRadix};
1515
use num::strconv;
1616
use option::Option;
1717
use slice::ImmutableVector;
18-
use str;
1918

2019
pub use core::i8::{BITS, BYTES, MIN, MAX};
2120

branches/try2/src/libstd/num/int.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use num::{ToStrRadix, FromStrRadix};
1515
use num::strconv;
1616
use option::Option;
1717
use slice::ImmutableVector;
18-
use str;
1918

2019
pub use core::int::{BITS, BYTES, MIN, MAX};
2120

branches/try2/src/libstd/num/int_macros.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,31 +62,31 @@ impl FromStrRadix for $T {
6262
/// ```
6363
#[inline]
6464
pub fn to_str_bytes<U>(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U {
65+
use io::{Writer, Seek};
6566
// The radix can be as low as 2, so we need at least 64 characters for a
6667
// base 2 number, and then we need another for a possible '-' character.
6768
let mut buf = [0u8, ..65];
68-
let mut cur = 0;
69-
strconv::int_to_str_bytes_common(n, radix, strconv::SignNeg, |i| {
70-
buf[cur] = i;
71-
cur += 1;
72-
});
73-
f(buf.slice(0, cur))
69+
let amt = {
70+
let mut wr = ::io::BufWriter::new(buf);
71+
if radix == 10 {
72+
(write!(&mut wr, "{}", n)).unwrap()
73+
} else {
74+
(write!(&mut wr, "{}", ::fmt::radix(n, radix as u8))).unwrap()
75+
}
76+
wr.tell().unwrap() as uint
77+
};
78+
f(buf.slice(0, amt))
7479
}
7580

7681
impl ToStrRadix for $T {
7782
/// Convert to a string in a given base.
7883
#[inline]
7984
fn to_str_radix(&self, radix: uint) -> ~str {
80-
use slice::Vector;
81-
use str::StrAllocating;
82-
83-
let mut buf = ::vec::Vec::new();
84-
strconv::int_to_str_bytes_common(*self, radix, strconv::SignNeg, |i| {
85-
buf.push(i);
86-
});
87-
// We know we generated valid utf-8, so we don't need to go through that
88-
// check.
89-
unsafe { str::raw::from_utf8(buf.as_slice()).to_owned() }
85+
if radix == 10 {
86+
format!("{}", *self)
87+
} else {
88+
format!("{}", ::fmt::radix(*self, radix as u8))
89+
}
9090
}
9191
}
9292

branches/try2/src/libstd/num/strconv.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ static NAN_BUF: [u8, ..3] = ['N' as u8, 'a' as u8, 'N' as u8];
170170
* # Failure
171171
* - Fails if `radix` < 2 or `radix` > 36.
172172
*/
173+
#[deprecated = "format!() and friends should be favored instead"]
173174
pub fn int_to_str_bytes_common<T: Int>(num: T, radix: uint, sign: SignFormat, f: |u8|) {
174175
assert!(2 <= radix && radix <= 36);
175176

@@ -258,6 +259,7 @@ pub fn int_to_str_bytes_common<T: Int>(num: T, radix: uint, sign: SignFormat, f:
258259
* - Fails if `radix` > 25 and `exp_format` is `ExpBin` due to conflict
259260
* between digit and exponent sign `'p'`.
260261
*/
262+
#[allow(deprecated)]
261263
pub fn float_to_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Float+
262264
Div<T,T>+Neg<T>+Rem<T,T>+Mul<T,T>>(
263265
num: T, radix: uint, negative_zero: bool,

branches/try2/src/libstd/num/u16.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use num::{ToStrRadix, FromStrRadix};
1515
use num::strconv;
1616
use option::Option;
1717
use slice::ImmutableVector;
18-
use str;
1918

2019
pub use core::u16::{BITS, BYTES, MIN, MAX};
2120

branches/try2/src/libstd/num/u32.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use num::{ToStrRadix, FromStrRadix};
1515
use num::strconv;
1616
use option::Option;
1717
use slice::ImmutableVector;
18-
use str;
1918

2019
pub use core::u32::{BITS, BYTES, MIN, MAX};
2120

branches/try2/src/libstd/num/u64.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use num::{ToStrRadix, FromStrRadix};
1515
use num::strconv;
1616
use option::Option;
1717
use slice::ImmutableVector;
18-
use str;
1918

2019
pub use core::u64::{BITS, BYTES, MIN, MAX};
2120

branches/try2/src/libstd/num/u8.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use num::{ToStrRadix, FromStrRadix};
1515
use num::strconv;
1616
use option::Option;
1717
use slice::ImmutableVector;
18-
use str;
1918

2019
pub use core::u8::{BITS, BYTES, MIN, MAX};
2120

branches/try2/src/libstd/num/uint.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use num::{ToStrRadix, FromStrRadix};
1515
use num::strconv;
1616
use option::Option;
1717
use slice::ImmutableVector;
18-
use str;
1918

2019
pub use core::uint::{BITS, BYTES, MIN, MAX};
2120

branches/try2/src/libstd/num/uint_macros.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,23 @@ impl FromStrRadix for $T {
6363
/// ```
6464
#[inline]
6565
pub fn to_str_bytes<U>(n: $T, radix: uint, f: |v: &[u8]| -> U) -> U {
66+
use io::{Writer, Seek};
6667
// The radix can be as low as 2, so we need at least 64 characters for a
67-
// base 2 number.
68-
let mut buf = [0u8, ..64];
69-
let mut cur = 0;
70-
strconv::int_to_str_bytes_common(n, radix, strconv::SignNone, |i| {
71-
buf[cur] = i;
72-
cur += 1;
73-
});
74-
f(buf.slice(0, cur))
68+
// base 2 number, and then we need another for a possible '-' character.
69+
let mut buf = [0u8, ..65];
70+
let amt = {
71+
let mut wr = ::io::BufWriter::new(buf);
72+
(write!(&mut wr, "{}", ::fmt::radix(n, radix as u8))).unwrap();
73+
wr.tell().unwrap() as uint
74+
};
75+
f(buf.slice(0, amt))
7576
}
7677

7778
impl ToStrRadix for $T {
7879
/// Convert to a string in a given base.
7980
#[inline]
8081
fn to_str_radix(&self, radix: uint) -> ~str {
81-
use slice::Vector;
82-
use str::StrAllocating;
83-
84-
let mut buf = ::vec::Vec::new();
85-
strconv::int_to_str_bytes_common(*self, radix, strconv::SignNone, |i| {
86-
buf.push(i);
87-
});
88-
// We know we generated valid utf-8, so we don't need to go through that
89-
// check.
90-
unsafe { str::raw::from_utf8(buf.as_slice()).to_owned() }
82+
format!("{}", ::fmt::radix(*self, radix as u8))
9183
}
9284
}
9385

0 commit comments

Comments
 (0)