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

Eliminate an unreachable codepath from String::from_utf8_lossy #91241

Merged
merged 1 commit into from
Nov 28, 2021

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Nov 26, 2021

Utf8Lossy's Iterator implementation ensures that only the final chunk has an empty slice for broken:

/// Empty iff iterator item is last.
pub broken: &'a [u8],

Thus the only way the first chunk could have an empty broken is if it is the final chunk, i.e. there is only one chunk total. And the only way that there could be one chunk total with an empty broken is if the whole input is valid utf8 and non-empty.

That condition has already been handled by an early return, so at the point that the first REPLACEMENT is being pushed, it's impossible for first_broken to be empty.

Utf8Lossy's Iterator implementation ensures that only the final chunk
has an empty slice for broken. Thus the only way the first chunk could
have an empty broken is if it is the final chunk, i.e. there is only one
chunk total. And the only way that there could be one chunk total is if
the whole input is valid utf8 and non-empty. That condition has already
been handled by an early return, so at the point that the first
REPLACEMENT is being pushed, it's impossible for first_broken to be
empty.
@rust-highfive
Copy link
Collaborator

r? @yaahc

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 26, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Nov 26, 2021

r? @oli-obk

@bors r+

@bors
Copy link
Contributor

bors commented Nov 26, 2021

📌 Commit 9125dd7 has been approved by oli-obk

@rust-highfive rust-highfive assigned oli-obk and unassigned yaahc Nov 26, 2021
@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 26, 2021
@bors
Copy link
Contributor

bors commented Nov 27, 2021

⌛ Testing commit 9125dd7 with merge 4919988...

@bors
Copy link
Contributor

bors commented Nov 28, 2021

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 4919988 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 28, 2021
@bors bors merged commit 4919988 into rust-lang:master Nov 28, 2021
@rustbot rustbot added this to the 1.59.0 milestone Nov 28, 2021
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (4919988): comparison url.

Summary: This benchmark run did not return any relevant changes.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

@dtolnay dtolnay deleted the firstchunk branch January 31, 2022 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants