mozilla/rust — pull request #12382 by bjz (2014-02-19 00:37:27+00:00)
Title: Fmt int

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`.

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. Initial benchmarks seem to indicate speedups of 30-50%:

~~~
type | radix | std::num::strconv | std::num::fmt
======|=======|========================|=======================
int | bin | 1787 ns/iter (+/- 198) | 1032 ns/iter (+/- 215)
int | oct | 677 ns/iter (+/- 64) | 422 ns/iter (+/- 42)
int | dec | 640 ns/iter (+/- 19) | 435 ns/iter (+/- 51)
int | hex | 635 ns/iter (+/- 54) | 386 ns/iter (+/- 15)
------|-------|------------------------|-----------------------
uint | bin | 1627 ns/iter (+/- 176) | 1028 ns/iter (+/- 110)
uint | oct | 632 ns/iter (+/- 30) | 421 ns/iter (+/- 27)
uint | dec | 599 ns/iter (+/- 28) | 410 ns/iter (+/- 45)
uint | hex | 507 ns/iter (+/- 54) | 393 ns/iter (+/- 38)
~~~