core: nit: Use `strip_prefix` instead of `starts_with` and subslicing.

As suggested by relrelb in a review note for #8820.
This commit is contained in:
TÖRÖK Attila 2023-01-13 20:23:29 +01:00 committed by Nathan Adams
parent 6138714fa7
commit ec462115ef
1 changed files with 2 additions and 2 deletions

View File

@ -87,9 +87,9 @@ pub fn remove_invalid_jpeg_data(data: &[u8]) -> Cow<[u8]> {
const SOI: u8 = 0xD8; // Start of image const SOI: u8 = 0xD8; // Start of image
const EOI: u8 = 0xD9; // End of image const EOI: u8 = 0xD9; // End of image
let mut data: Cow<[u8]> = if data.starts_with(&[0xFF, EOI, 0xFF, SOI]) { let mut data: Cow<[u8]> = if let Some(stripped) = data.strip_prefix(&[0xFF, EOI, 0xFF, SOI]) {
// Common case: usually the sequence is at the beginning as the spec says, so adjust the slice to avoid a copy. // Common case: usually the sequence is at the beginning as the spec says, so adjust the slice to avoid a copy.
data[4..].into() stripped.into()
} else { } else {
// Parse the JPEG markers searching for the 0xFFD9FFD8 marker sequence to splice out. // Parse the JPEG markers searching for the 0xFFD9FFD8 marker sequence to splice out.
// We only have to search up to the SOF0 marker. // We only have to search up to the SOF0 marker.