Skip to content
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

use from_utf8_unchecked in the fmt::Display implementation of Value #751

Merged
merged 1 commit into from Feb 5, 2021

Conversation

icewind1991
Copy link
Contributor

Since the serializer only emits valid utf8 by default we can remove the checks that the data being formatted is valid.

WriterFormatter has been moved into it's own little module to enforce using it's new method to convey the unsafe requirements.
the safety requirements that the serializer only emits valid utf8 is already assumed by the existing to_string methods.

Marking WriterFormatter as unsafe is not strictly necesarry as it is already contained within the module bounds, but this way it's a bit more explicit about the assumptions being made.

this speeds up formatting large Values by about 33% in my testing.

`WriterFormatter` has been moved into it's own little module to enforce using it's `new` method to convey the unsafe requirements.
the safety requirements that the serializer only emits valid utf8 is already assumed by the existing `to_string` methods.

this speeds up formatting large `Value`s by about 33% in my testing
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dtolnay dtolnay merged commit e81e7d9 into serde-rs:master Feb 5, 2021
@icewind1991 icewind1991 deleted the value-display-utf8-unchecked branch February 6, 2021 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants