Optimize various case-insensitive comparisons.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2026-02-12 09:01:46 +00:00
parent 814cbc2f37
commit 994e1d12a7
5 changed files with 9 additions and 9 deletions

View File

@@ -133,8 +133,8 @@ pub(crate) async fn get_state_events_for_key_route(
let event_format = body
.format
.as_ref()
.is_some_and(|f| f.to_lowercase().eq("event"));
.as_deref()
.is_some_and(|f| f.eq_ignore_ascii_case("event"));
Ok(get_state_event_for_key::v3::Response {
content: event_format.or(|| event.get_content_as_value()),

View File

@@ -224,7 +224,7 @@ async fn download_html(&self, _url: &str) -> Result<UrlPreviewData> {
pub fn url_preview_allowed(&self, url: &Url) -> bool {
if ["http", "https"]
.iter()
.all(|&scheme| scheme != url.scheme().to_lowercase())
.all(|&scheme| !scheme.eq_ignore_ascii_case(url.scheme()))
{
debug!("Ignoring non-HTTP/HTTPS URL to preview: {}", url);
return false;

View File

@@ -69,11 +69,11 @@ pub fn get_config(&self, id: &str) -> Result<Provider> {
if let Some(provider) = providers
.values()
.find(|config| config.brand == id.to_lowercase())
.find(|config| config.brand.eq_ignore_ascii_case(id))
.filter(|_| {
providers
.values()
.filter(|config| config.brand == id.to_lowercase())
.filter(|config| config.brand.eq_ignore_ascii_case(id))
.count()
.eq(&1)
})
@@ -97,11 +97,11 @@ async fn get_cached(&self, id: &str) -> Option<Provider> {
providers
.values()
.find(|provider| provider.brand == id.to_lowercase())
.find(|provider| provider.brand.eq_ignore_ascii_case(id))
.filter(|_| {
providers
.values()
.filter(|provider| provider.brand == id.to_lowercase())
.filter(|provider| provider.brand.eq_ignore_ascii_case(id))
.count()
.eq(&1)
})

View File

@@ -104,7 +104,7 @@ pub async fn set_pusher(
if ["http", "https"]
.iter()
.all(|&scheme| scheme != url.scheme().to_lowercase())
.all(|&scheme| !scheme.eq_ignore_ascii_case(url.scheme()))
{
return Err!(Request(InvalidParam(
warn!(%url, "HTTP pusher URL is not a valid HTTP/HTTPS URL")

View File

@@ -97,7 +97,7 @@ async fn send_notice<Pdu: Event>(
if ["http", "https"]
.iter()
.all(|&scheme| scheme != url.scheme().to_lowercase())
.all(|&scheme| !scheme.eq_ignore_ascii_case(url.scheme()))
{
return Err!(Request(InvalidParam(
warn!(%url, "HTTP pusher URL is not a valid HTTP/HTTPS URL")