-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Tracking Issue for integer formatting into a fixed-size buffer #138215
Comments
Implementation should be a straightforward refactoring of the existing code, but I don't know if and when I'll have time to do that, so I'd welcome if someone else wants to implement it. @rustbot label E-easy E-help-wanted |
Hi, I'd love to implement this |
In my experience with itoa, one problem with the equally sized buffers for all int types u8 to u128 is that a memcpy is generated when there is no need to. A u8 won't stringify to 20 bytes and it won't benefit from "smarter" copy implementations. A 3 byte buffer for u8, 4 bytes for i8, … would generate much better byte code. I guess this will be the same with this feature. |
As I understand it, the main problem with the memcpy is that the number of bytes to copy is variable (determined at runtime), not that the underlying buffer is oversized. An However, that would be a more invasive change to the current standard library implementation and to the API sketch that was accepted in the ACP. Of course I’d be happy to see an even better solution for this functionality but after thinking about it for quite some time, I’m not sure of this is possible without tough trade-offs. So I’d rather see Rust ship something that’s going to work well for the libraries that happily use |
By refactor, did you mean actually create an implementation from scratch? Looking forward to learning a lot by implementing this feature. |
I mean that the code that implements the formatting doesn’t have to change except being refactored to expose it’s existing functionality in a new way (accept a buffer as argument instead of writing into its local variable |
Feature gate:
#![feature(int_format_into)]
This is a tracking issue for efficient decimal integer formatting into a fixed-size buffer.
Public API
Steps / History
Unresolved Questions
&[ascii::Char]
in the future? Efficient integer formatting into fixed-size buffer libs-team#546 (comment)NumBuffer
beNumBuffer<$Int>
so that the reserved space can be tailored to the specific integer's size? Not a big difference with current integer types, but may be significant if we gainu8192
in the future.core::num::NumBuffer
.Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: