Skip to content

Commit 48168d0

Browse files
committed
simplify
1 parent b65f1ec commit 48168d0

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

portable/src/implementation/fallback.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,15 @@ impl Utf8ValidatorImp {
7070
}
7171
};
7272
let rem_input = input.len() - e.valid_up_to() - 1;
73-
if rem_input >= self.expected_cont_bytes as usize {
74-
// too many continuation bytes so they are not valid
75-
self.err = true;
76-
return;
77-
}
78-
for i in 0..rem_input {
73+
for i in 0..rem_input.min(self.expected_cont_bytes as usize) {
7974
if input[e.valid_up_to() + i + 1] & 0b1100_0000 != 0b1000_0000 {
8075
// not a continuation byte
8176
self.err = true;
8277
return;
8378
}
8479
self.expected_cont_bytes -= 1;
8580
}
81+
debug_assert!(self.expected_cont_bytes != 0); // otherwise from_utf8 would not have errored
8682
}
8783
}
8884

0 commit comments

Comments
 (0)