From 951dead7b411c5d8925c7f8921dad6d286ec599a Mon Sep 17 00:00:00 2001 From: haoqixu Date: Thu, 22 Aug 2024 17:30:45 +0800 Subject: [PATCH] refactor(core/services-oss): remove the `starts_with` The `strip_prefix()` method returns None if the string doesn't start with the prefix, so we don't need to check the prefix before stripping. This change removes the `starts_with()` and simplifies codes. --- core/src/services/oss/core.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/core/src/services/oss/core.rs b/core/src/services/oss/core.rs index 8b2374b36dc..d4dff76348e 100644 --- a/core/src/services/oss/core.rs +++ b/core/src/services/oss/core.rs @@ -224,16 +224,13 @@ impl OssCore { let data: HashMap = headers .iter() .filter_map(|(key, _)| { - if key.as_str().starts_with(user_metadata_prefix) { - if let Ok(Some(value)) = parse_header_to_str(headers, key) { - let key_str = key.to_string(); - let stripped_key = key_str - .strip_prefix(user_metadata_prefix) - .expect("strip prefix must succeed"); - return Some((stripped_key.to_string(), value.to_string())); - } - } - None + key.as_str() + .strip_prefix(user_metadata_prefix) + .and_then(|stripped_key| { + parse_header_to_str(headers, key) + .unwrap_or(None) + .map(|val| (stripped_key.to_string(), val.to_string())) + }) }) .collect(); if !data.is_empty() {