diff options
| author | bors <bors@rust-lang.org> | 2014-02-21 16:36:52 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-02-21 16:36:52 -0800 |
| commit | d2f73abf10ff72270f36d73e91851511fd1e0580 (patch) | |
| tree | 457abe392a3416bc600d1b167c91bbb71f5f15a9 /src/libstd/num/int_macros.rs | |
| parent | 87c7e1542c386a06a5fb1de63c36df8b95088231 (diff) | |
| parent | 6943acd1a50b0c4d0d95e298c151aa796ae05269 (diff) | |
| download | rust-d2f73abf10ff72270f36d73e91851511fd1e0580.tar.gz rust-d2f73abf10ff72270f36d73e91851511fd1e0580.zip | |
auto merge of #12382 : bjz/rust/fmt-int, r=alexcrichton
This is PR is the beginning of a complete rewrite and ultimate removal of the `std::num::strconv` module (see #6220), and the removal of the `ToStrRadix` trait in favour of using the `std::fmt` functionality directly. This should make for a cleaner API, encourage less allocation, and make the implementation more comprehensible .
The `Formatter::{pad_integral, with_padding}` methods have also been refactored make things easier to understand.
The formatting tests for integers have been moved out of `run-pass/ifmt.rs` in order to provide more immediate feedback when building using `make check-stage2-std NO_REBUILD=1`.
Arbitrary radixes are now easier to use in format strings. For example:
~~~rust
assert_eq!(format!("{:04}", radix(3, 2)), ~"0011");
~~~
The benchmarks have been standardised between `std::num::strconv` and `std::num::fmt` to make it easier to compare the performance of the different implementations.
~~~
type | radix | std::num::strconv | std::num::fmt
======|=======|========================|======================
int | bin | 1748 ns/iter (+/- 150) | 321 ns/iter (+/- 25)
int | oct | 706 ns/iter (+/- 53) | 179 ns/iter (+/- 22)
int | dec | 640 ns/iter (+/- 59) | 207 ns/iter (+/- 10)
int | hex | 637 ns/iter (+/- 77) | 205 ns/iter (+/- 19)
int | 36 | 446 ns/iter (+/- 30) | 309 ns/iter (+/- 20)
------|-------|------------------------|----------------------
uint | bin | 1724 ns/iter (+/- 159) | 322 ns/iter (+/- 13)
uint | oct | 663 ns/iter (+/- 25) | 175 ns/iter (+/- 7)
uint | dec | 613 ns/iter (+/- 30) | 186 ns/iter (+/- 6)
uint | hex | 519 ns/iter (+/- 44) | 207 ns/iter (+/- 20)
uint | 36 | 418 ns/iter (+/- 16) | 308 ns/iter (+/- 32)
~~~
Diffstat (limited to 'src/libstd/num/int_macros.rs')
| -rw-r--r-- | src/libstd/num/int_macros.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs index 7f45b5deb18..43a70190812 100644 --- a/src/libstd/num/int_macros.rs +++ b/src/libstd/num/int_macros.rs @@ -277,7 +277,7 @@ impl ToStr for $T { /// Convert to a string in base 10. #[inline] fn to_str(&self) -> ~str { - self.to_str_radix(10) + format!("{:d}", *self) } } |
