reduce allocation on checking DOM attributes and do not hard-code number of elements of array constant

`to_lower` allocates new string but the allocation is not necessary
here.
This commit is contained in:
rhysd 2020-01-04 07:49:39 +09:00
parent 63e19998d0
commit ce03e0e487
2 changed files with 10 additions and 4 deletions

View file

@ -12,7 +12,7 @@ use std::collections::HashMap;
use std::default::Default;
use utils::{data_to_dataurl, is_valid_url, resolve_css_imports, resolve_url, url_has_protocol};
const ICON_VALUES: [&str; 5] = [
const ICON_VALUES: &[&str] = &[
"icon",
"shortcut icon",
"mask-icon",
@ -37,7 +37,10 @@ pub fn get_node_name(node: &Handle) -> String {
}
pub fn is_icon(attr_value: &str) -> bool {
ICON_VALUES.contains(&&*attr_value.to_lowercase())
ICON_VALUES
.iter()
.find(|a| attr_value.eq_ignore_ascii_case(a))
.is_some()
}
pub fn walk_and_embed_assets(

View file

@ -1,4 +1,4 @@
const JS_DOM_EVENT_ATTRS: [&str; 21] = [
const JS_DOM_EVENT_ATTRS: &[&str] = &[
// Input
"onfocus",
"onblur",
@ -28,5 +28,8 @@ const JS_DOM_EVENT_ATTRS: [&str; 21] = [
// Returns true if DOM attribute name matches a native JavaScript event handler
pub fn attr_is_event_handler(attr_name: &str) -> bool {
JS_DOM_EVENT_ATTRS.contains(&attr_name.to_lowercase().as_str())
JS_DOM_EVENT_ATTRS
.iter()
.find(|a| attr_name.eq_ignore_ascii_case(a))
.is_some()
}