Skip to content

Commit

Permalink
refactor(core/services-oss): remove the starts_with (#5036)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
haoqixu authored Aug 22, 2024
1 parent 61c0546 commit 5463e20
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions core/src/services/oss/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,13 @@ impl OssCore {
let data: HashMap<String, String> = 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() {
Expand Down

0 comments on commit 5463e20

Please sign in to comment.