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:
parent
63e19998d0
commit
ce03e0e487
2 changed files with 10 additions and 4 deletions
|
@ -12,7 +12,7 @@ use std::collections::HashMap;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use utils::{data_to_dataurl, is_valid_url, resolve_css_imports, resolve_url, url_has_protocol};
|
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",
|
"icon",
|
||||||
"shortcut icon",
|
"shortcut icon",
|
||||||
"mask-icon",
|
"mask-icon",
|
||||||
|
@ -37,7 +37,10 @@ pub fn get_node_name(node: &Handle) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_icon(attr_value: &str) -> bool {
|
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(
|
pub fn walk_and_embed_assets(
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const JS_DOM_EVENT_ATTRS: [&str; 21] = [
|
const JS_DOM_EVENT_ATTRS: &[&str] = &[
|
||||||
// Input
|
// Input
|
||||||
"onfocus",
|
"onfocus",
|
||||||
"onblur",
|
"onblur",
|
||||||
|
@ -28,5 +28,8 @@ const JS_DOM_EVENT_ATTRS: [&str; 21] = [
|
||||||
|
|
||||||
// Returns true if DOM attribute name matches a native JavaScript event handler
|
// Returns true if DOM attribute name matches a native JavaScript event handler
|
||||||
pub fn attr_is_event_handler(attr_name: &str) -> bool {
|
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()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue