From ec462115ef986370b88cb6172722740e43cbfdcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=96R=C3=96K=20Attila?= Date: Fri, 13 Jan 2023 20:23:29 +0100 Subject: [PATCH] core: nit: Use `strip_prefix` instead of `starts_with` and subslicing. As suggested by relrelb in a review note for #8820. --- render/src/utils.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/render/src/utils.rs b/render/src/utils.rs index 3de882659..0de05ef93 100644 --- a/render/src/utils.rs +++ b/render/src/utils.rs @@ -87,9 +87,9 @@ pub fn remove_invalid_jpeg_data(data: &[u8]) -> Cow<[u8]> { const SOI: u8 = 0xD8; // Start 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. - data[4..].into() + stripped.into() } else { // Parse the JPEG markers searching for the 0xFFD9FFD8 marker sequence to splice out. // We only have to search up to the SOF0 marker.