-
Notifications
You must be signed in to change notification settings - Fork 47
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
Add && Impl new trait ToCompactStr #16
Conversation
Thanks for the PR! I really like the idea of a |
Sure, I will wait for #12 |
Hey @NobodyXu, now that I think the idea of a For efficiently converting number types to strings take a look at |
Yes, sure.
Hmmm, I don't like the idea of implementing only for common types, as it would make For common number types, maybe we can provide a optional specialization for them using |
Fair enough, that makes sense to me! Ugh I wish specialization was stable. Regardless, |
I am quite busy recently, so it might take me some time to implement it. |
Signed-off-by: Jiahao XU <[email protected]>
Sorry I accidentally closed this PR, now it is reopened. |
@ParkMyCar I have implemented trait I will implement the specialisation later, but now you can probably start looking at my code and providing me with feedback so that we can ensure the implementation is correct before doing any optimization. |
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.
Thanks for doing this work!
Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
Impl new function `InlineString::from_fmt` to avoid copying the buffer for `InlineString`. Signed-off-by: Jiahao XU <[email protected]>
into `InlineString::from_fmt` Signed-off-by: Jiahao XU <[email protected]>
Instead of using `std::io::Cursor`. Signed-off-by: Jiahao XU <[email protected]>
`[u8; _]::as_mut_slice` is only present in rust >= 1.57.0 Signed-off-by: Jiahao XU <[email protected]>
I just realized that I am now thinking of adding another trait It is just unfortunate that Rust doesn't have specialisation stabilised. |
I also asked the question sagebind/castaway#5 on Edit: Turns out it is actually feasible sagebind/castaway#6 |
With sagebind/castaway#6 merged in and released as https://github.com/sagebind/castaway/releases/tag/0.2.0, this is no longer an issue. I will continue my work on specialisation for |
Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
`castaway::cast!` cannot cast reference of `T: ?Sized` to primitive types Signed-off-by: Jiahao XU <[email protected]>
Use `Sink(0)` directly to make optimization easier. Signed-off-by: Jiahao XU <[email protected]>
to avoid using macro `count!` in `Repr::from_fmt`, which uses `core::format_args!`, making it harder to optimize. Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
For `LifetimeFree` impl for `NonZeroUsize`. Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
Test different float values in the same `assert_eq` so that if one `assert_eq`, we can obtain value of the formatting of all float values we provided. Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
Sorry I used the wrong command. |
Signed-off-by: Jiahao XU <[email protected]>
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.
Thanks for all the work here @NobodyXu! I've been pretty busy lately so haven't had a chance to look super in-depth, but I think we're getting close!
Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
Instead of calling `Repr::from_fmt`, then forward it to `Inline::from_fmt` or formatting into preallocated `String`, this commit uses `CompactStr::with_capacity` to preallocate required space ahead of time to avoid repeated heap allocation and copying, then use `fmt::Write` implementation for `CompactStr` to format value into the `CompactStr` with preallocated space. Signed-off-by: Jiahao XU <[email protected]>
- Module `io` only present in `std`, while `fmt` present in `core`. - `io::Write` requires additional `flush` method to be implemented. - `io::Write::write` requires the len of bytes written to be returned. Signed-off-by: Jiahao XU <[email protected]>
by implementing `fmt::Write::write_char` Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
To make this PR easier to review. Signed-off-by: Jiahao XU <[email protected]>
Signed-off-by: Jiahao XU <[email protected]>
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.
Thanks for all the hard work here @NobodyXu and making all the changes I asked for!
Looks like there's just one failing test on PowerPC Little Endian with float formatting? If we can fix the test that would be great, otherwise I'm fine with ignoring it. Once you make that change we can merge!
Thanks again for all the work! 🙂
Unfortunately that is a compiler bug rust-lang/rust#96306 which I cannot fix. @ParkMyCar I think this PR is ready for merging as the failure on powepc64le has nothing to do with this PR. |
Signed-off-by: Jiahao XU <[email protected]>
Merging, thanks @NobodyXu! |
@ParkMyCar Now that we have more unit tests and fuzzing added for |
Mayhem fork
Similar to
std::string::ToString
,ToCompactStr
convert any value implementsfmt::Display
into aCompactStr
efficiently.However, due to the fact that
Arc::<[MaybeUninit<T>]>
is still unstable, there is no way to implementHeapString
efficiently without first creating aString
, then copy it onto the buffer and deallocate the originalString
.It seems that the compiler may not be able to optimize these calls, especially with
std::format!
callingformat
.Signed-off-by: Jiahao XU [email protected]