Improve attr min performance
This commit is contained in:
parent
3831a2605e
commit
472c4d8fac
|
@ -108,7 +108,7 @@ fn build_unquoted_replacer() -> Replacer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If spec compliance is required, these characters must also be encoded in an unquoted attr value,
|
// If spec compliance is required, these characters must also be encoded in an unquoted attr value,
|
||||||
// as well as `<` and `>`.
|
// as well as whitespace, `<`, and `>`.
|
||||||
static WHATWG_UNQUOTED: &[(u8, &[u8])] = &[
|
static WHATWG_UNQUOTED: &[(u8, &[u8])] = &[
|
||||||
(b'"', b"""),
|
(b'"', b"""),
|
||||||
(b'\'', b"'"),
|
(b'\'', b"'"),
|
||||||
|
@ -240,29 +240,35 @@ pub fn encode_using_single_quotes(val: &[u8]) -> AttrMinifiedValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn encode_unquoted(val: &[u8], whatwg: bool) -> AttrMinifiedValue {
|
pub fn encode_unquoted(val: &[u8], whatwg: bool) -> AttrMinifiedValue {
|
||||||
let data = if whatwg {
|
if whatwg {
|
||||||
WHATWG_UNQUOTED_QUOTED_REPLACER.replace_all(val)
|
AttrMinifiedValue {
|
||||||
|
quoted: false,
|
||||||
|
prefix: b"",
|
||||||
|
data: WHATWG_UNQUOTED_QUOTED_REPLACER.replace_all(val),
|
||||||
|
start: 0,
|
||||||
|
suffix: b"",
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
UNQUOTED_QUOTED_REPLACER.replace_all(val)
|
let data = UNQUOTED_QUOTED_REPLACER.replace_all(val);
|
||||||
};
|
let prefix: &'static [u8] = match data.get(0) {
|
||||||
let prefix: &'static [u8] = match data.get(0) {
|
Some(b'"') => match data.get(1) {
|
||||||
Some(b'"') => match data.get(1) {
|
Some(&c2) if DIGIT[c2] || c2 == b';' => b""",
|
||||||
Some(&c2) if DIGIT[c2] || c2 == b';' => b""",
|
_ => b""",
|
||||||
_ => b""",
|
},
|
||||||
},
|
Some(b'\'') => match data.get(1) {
|
||||||
Some(b'\'') => match data.get(1) {
|
Some(&c2) if DIGIT[c2] || c2 == b';' => b"'",
|
||||||
Some(&c2) if DIGIT[c2] || c2 == b';' => b"'",
|
_ => b"'",
|
||||||
_ => b"'",
|
},
|
||||||
},
|
_ => b"",
|
||||||
_ => b"",
|
};
|
||||||
};
|
let start = if !prefix.is_empty() { 1 } else { 0 };
|
||||||
let start = if !prefix.is_empty() { 1 } else { 0 };
|
AttrMinifiedValue {
|
||||||
AttrMinifiedValue {
|
quoted: false,
|
||||||
quoted: false,
|
prefix,
|
||||||
prefix,
|
data,
|
||||||
data,
|
start,
|
||||||
start,
|
suffix: b"",
|
||||||
suffix: b"",
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue