perf: avoid making copies of strings (#412)

This commit is contained in:
Denis Andrejew
2023-01-18 17:47:15 +01:00
committed by GitHub
parent e79cdaa9d9
commit c7665d7f35

View File

@ -60,10 +60,11 @@ impl CustomerInterface for Store {
.map_err(Into::into) .map_err(Into::into)
.into_report()?; .into_report()?;
maybe_customer.map_or(Ok(None), |customer| { maybe_customer.map_or(Ok(None), |customer| {
if customer.name == Some(REDACTED.to_string()) { // in the future, once #![feature(is_some_and)] is stable, we can make this more concise:
Err(errors::StorageError::CustomerRedacted)? // `if customer.name.is_some_and(|ref name| name == REDACTED) ...`
} else { match customer.name {
Ok(Some(customer)) Some(ref name) if name == REDACTED => Err(errors::StorageError::CustomerRedacted)?,
_ => Ok(Some(customer)),
} }
}) })
} }
@ -97,10 +98,9 @@ impl CustomerInterface for Store {
.await .await
.map_err(Into::into) .map_err(Into::into)
.into_report()?; .into_report()?;
if customer.name == Some(REDACTED.to_string()) { match customer.name {
Err(errors::StorageError::CustomerRedacted)? Some(ref name) if name == REDACTED => Err(errors::StorageError::CustomerRedacted)?,
} else { _ => Ok(customer),
Ok(customer)
} }
} }