Skip to content

Commit 5e37a31

Browse files
Rollup merge of rust-lang#155855 - ChrisDenton:remove-unsafe-get, r=Mark-Simulacrum
Remove unnecessary `get_unchecked` My benchmarking did not show any issue with using the safe method instead so I assume this isn't an issue any more. But let's do a perf run to be sure.
2 parents e666d3e + 69cc5fa commit 5e37a31

1 file changed

Lines changed: 1 addition & 6 deletions

File tree

library/core/src/str/lossy.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,7 @@ impl<'a> Iterator for Utf8Chunks<'a> {
211211

212212
let mut i = 0;
213213
let mut valid_up_to = 0;
214-
while i < self.source.len() {
215-
// SAFETY: `i < self.source.len()` per previous line.
216-
// For some reason the following are both significantly slower:
217-
// while let Some(&byte) = self.source.get(i) {
218-
// while let Some(byte) = self.source.get(i).copied() {
219-
let byte = unsafe { *self.source.get_unchecked(i) };
214+
while let Some(byte) = self.source.get(i).copied() {
220215
i += 1;
221216

222217
if byte < 128 {

0 commit comments

Comments
 (0)