-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Implement int_format_into
feature
#142098
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Failed to set assignee to
|
assert_eq!(ret, value); | ||
|
||
let mut buffer = NumBuffer::<$int>::new(); | ||
assert_eq!(value.format_into(&mut buffer), s.as_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since format_into
is not part of a trait, I needed to switch from a function to a macro to avoid the generics limitations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could write and implement a trait right here, in the test - right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could indeed, but would be better than the current code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Less churn; other than that I don't have strong feelings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If someone else agrees with you I'll make the change (lazyness++ 😆).
r? @Amanieu |
This comment has been minimized.
This comment has been minimized.
1d9a06e
to
2589402
Compare
d11cb44
to
70ab4e0
Compare
This comment has been minimized.
This comment has been minimized.
70ab4e0
to
3eecb24
Compare
3eecb24
to
2f869c5
Compare
Applied suggestions and opened another PR for the number of digits of u128 computation to not add even more changes to this PR. |
2f869c5
to
9324432
Compare
☔ The latest upstream changes (presumably #142133) made this pull request unmergeable. Please resolve the merge conflicts. |
9324432
to
4733100
Compare
Fixed merge conflict. |
4733100
to
61cc5f3
Compare
Maybe you want to take a look at this one too @tgross35 ? :) |
61cc5f3
to
e5c6e02
Compare
I improved docs for the new API and rebased too. |
…egers, r=tgross35 Use a distinct `ToString` implementation for `u128` and `i128` Part of #135543. Follow-up of #136264. When working on #142098, I realized that `i128` and `u128` could also benefit from a distinct `ToString` implementation so here it. The last commit is just me realizing that I forgot to add the format tests for `usize` and `isize`. Here is the bench comparison: | bench name | last nightly | with this PR | diff | |-|-|-|-| | bench_i128 | 29.25 ns/iter (+/- 0.66) | 17.52 ns/iter (+/- 0.7) | -40.1% | | bench_u128 | 34.06 ns/iter (+/- 0.21) | 16.1 ns/iter (+/- 0.6) | -52.7% | I used this code to test: ```rust #![feature(test)] extern crate test; use test::{Bencher, black_box}; #[inline(always)] fn convert_to_string<T: ToString>(n: T) -> String { n.to_string() } macro_rules! decl_benches { ($($name:ident: $ty:ident,)+) => { $( #[bench] fn $name(c: &mut Bencher) { c.iter(|| convert_to_string(black_box({ let nb: $ty = 20; nb }))); } )+ } } decl_benches! { bench_u128: u128, bench_i128: i128, } ```
☔ The latest upstream changes (presumably #142294) made this pull request unmergeable. Please resolve the merge conflicts. |
e5c6e02
to
1b59ede
Compare
Fixed merge conflict. |
☔ The latest upstream changes (presumably #142795) made this pull request unmergeable. Please resolve the merge conflicts. |
…egers, r=tgross35 Use a distinct `ToString` implementation for `u128` and `i128` Part of rust-lang/rust#135543. Follow-up of rust-lang/rust#136264. When working on rust-lang/rust#142098, I realized that `i128` and `u128` could also benefit from a distinct `ToString` implementation so here it. The last commit is just me realizing that I forgot to add the format tests for `usize` and `isize`. Here is the bench comparison: | bench name | last nightly | with this PR | diff | |-|-|-|-| | bench_i128 | 29.25 ns/iter (+/- 0.66) | 17.52 ns/iter (+/- 0.7) | -40.1% | | bench_u128 | 34.06 ns/iter (+/- 0.21) | 16.1 ns/iter (+/- 0.6) | -52.7% | I used this code to test: ```rust #![feature(test)] extern crate test; use test::{Bencher, black_box}; #[inline(always)] fn convert_to_string<T: ToString>(n: T) -> String { n.to_string() } macro_rules! decl_benches { ($($name:ident: $ty:ident,)+) => { $( #[bench] fn $name(c: &mut Bencher) { c.iter(|| convert_to_string(black_box({ let nb: $ty = 20; nb }))); } )+ } } decl_benches! { bench_u128: u128, bench_i128: i128, } ```
/// Returns the length of the buffer. | ||
#[unstable(feature = "int_format_into", issue = "138215")] | ||
pub const fn len(&self) -> usize { | ||
self.buf.len() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will always return 40, is this intended?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now it's always 40
but I do hope in the future it will depend on the integer size when associated const support will be more advanced.
…egers, r=tgross35 Use a distinct `ToString` implementation for `u128` and `i128` Part of rust-lang/rust#135543. Follow-up of rust-lang/rust#136264. When working on rust-lang/rust#142098, I realized that `i128` and `u128` could also benefit from a distinct `ToString` implementation so here it. The last commit is just me realizing that I forgot to add the format tests for `usize` and `isize`. Here is the bench comparison: | bench name | last nightly | with this PR | diff | |-|-|-|-| | bench_i128 | 29.25 ns/iter (+/- 0.66) | 17.52 ns/iter (+/- 0.7) | -40.1% | | bench_u128 | 34.06 ns/iter (+/- 0.21) | 16.1 ns/iter (+/- 0.6) | -52.7% | I used this code to test: ```rust #![feature(test)] extern crate test; use test::{Bencher, black_box}; #[inline(always)] fn convert_to_string<T: ToString>(n: T) -> String { n.to_string() } macro_rules! decl_benches { ($($name:ident: $ty:ident,)+) => { $( #[bench] fn $name(c: &mut Bencher) { c.iter(|| convert_to_string(black_box({ let nb: $ty = 20; nb }))); } )+ } } decl_benches! { bench_u128: u128, bench_i128: i128, } ```
…egers, r=tgross35 Use a distinct `ToString` implementation for `u128` and `i128` Part of rust-lang/rust#135543. Follow-up of rust-lang/rust#136264. When working on rust-lang/rust#142098, I realized that `i128` and `u128` could also benefit from a distinct `ToString` implementation so here it. The last commit is just me realizing that I forgot to add the format tests for `usize` and `isize`. Here is the bench comparison: | bench name | last nightly | with this PR | diff | |-|-|-|-| | bench_i128 | 29.25 ns/iter (+/- 0.66) | 17.52 ns/iter (+/- 0.7) | -40.1% | | bench_u128 | 34.06 ns/iter (+/- 0.21) | 16.1 ns/iter (+/- 0.6) | -52.7% | I used this code to test: ```rust #![feature(test)] extern crate test; use test::{Bencher, black_box}; #[inline(always)] fn convert_to_string<T: ToString>(n: T) -> String { n.to_string() } macro_rules! decl_benches { ($($name:ident: $ty:ident,)+) => { $( #[bench] fn $name(c: &mut Bencher) { c.iter(|| convert_to_string(black_box({ let nb: $ty = 20; nb }))); } )+ } } decl_benches! { bench_u128: u128, bench_i128: i128, } ```
1b59ede
to
e8eefc7
Compare
I took over #138338 with @madhav-madhusoodanan's approval.
Since #136264, a lot of changes happened so I made use of them to reduce the number of changes.
ACP approval: rust-lang/libs-team#546 (comment)
Associated Issue
r? @hanna-kruppe