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

@icewind1991 icewind1991 commented Feb 5, 2021

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
@dtolnay
dtolnay approved these changes Feb 5, 2021
Copy link
Member

@dtolnay dtolnay left a comment

Thanks!

@dtolnay dtolnay merged commit e81e7d9 into serde-rs:master Feb 5, 2021
11 of 12 checks passed
11 of 12 checks passed
Rust nightly
Details
Rust nightly (windows)
Details
Rust beta
Details
Rust stable
Details
Rust 1.45.0
Details
Rust 1.40.0
Details
Rust 1.36.0
Details
Rust 1.31.0 Rust 1.31.0
Details
Rust stable (windows)
Details
Rust 1.36.0
Details
Clippy
Details
Fuzz
Details
@icewind1991 icewind1991 deleted the icewind1991:value-display-utf8-unchecked branch Feb 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants