perf(token): Reduce splitting overhead by about 10%

This commit is contained in:
Ed Page committed 2025-04-23 14:09:18 -05:00
1 parent 8c4898131f
commit 400cd2fad6
1 file changed
+24 -13
+24 -13
View File
@@ -187,18 +187,18 @@ mod parser {
// CAUTION: If adding an ignorable literal, if it doesn't start with `is_xid_continue`,
// - Update `is_ignore_char` to make sure `other` doesn't eat it all up
// - Make sure you always consume it
terminated(uuid_literal, peek(sep1)),
terminated(email_literal, peek(sep1)),
terminated(url_literal, peek(sep1)),
terminated(jwt, peek(sep1)),
terminated(base64_literal, peek(sep1)), // base64 should be quoted or something
terminated(hash_literal, peek(sep1)),
terminated(ordinal_literal, peek(sep1)),
terminated(hex_literal, peek(sep1)),
terminated(dec_literal, peek(sep1)), // Allow digit-prefixed words
terminated(css_color, peek(sep1)),
c_escape,
printf,
terminated(uuid_literal, sep1),
terminated(email_literal, sep1),
terminated(url_literal, sep1),
terminated(jwt, sep1),
terminated(base64_literal, sep1), // base64 should be quoted or something
terminated(hash_literal, sep1),
terminated(ordinal_literal, sep1),
terminated(hex_literal, sep1),
terminated(dec_literal, sep1), // Allow digit-prefixed words
terminated(css_color, sep1),
terminated(c_escape, sep1),
terminated(printf, sep1),
other,
))),
)
@@ -212,7 +212,8 @@ mod parser {
<T as Stream>::Token: AsChar + Copy,
{
alt((
one_of(|c| !is_xid_continue(c)).take(),
take_while(1.., is_ignore_char),
peek(one_of(|c| !is_xid_continue(c))).take(),
eof.map(|_| <T as Stream>::Slice::default()),
))
.parse_next(input)
@@ -1439,6 +1440,11 @@ mod test {
case: None,
offset: 25,
},
Identifier {
token: "src",
case: None,
offset: 77,
},
Identifier {
token: "rs",
case: None,
@@ -1458,6 +1464,11 @@ mod test {
case: None,
offset: 25,
},
Identifier {
token: "src",
case: None,
offset: 77,
},
Identifier {
token: "rs",
case: None,