Skip to content

Commit 8e055c4

Browse files
committed
Include more ASCII characters in nodeprep fast path
Not every character is included, it’s missing '!', ';', '=' and '?' which each add one branch, for almost no usage in the wild. From a very unscientific dataset formed by my personal roster + my bookmarks, this reduces the time to parse all JIDs once from 128 µs to 35 µs.
1 parent 3ee4289 commit 8e055c4

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,10 @@ pub fn nameprep(s: &str) -> Result<Cow<'_, str>, Error> {
179179
///
180180
/// [RFC 3920, Appendix A]: https://tools.ietf.org/html/rfc3920#appendix-A
181181
pub fn nodeprep(s: &str) -> Result<Cow<'_, str>, Error> {
182-
// fast path for ascii text
183-
if s.chars().all(|c| {
184-
c.is_ascii_lowercase()
185-
&& !tables::ascii_control_character(c)
186-
&& !prohibited_node_character(c)
187-
}) {
182+
// fast path for common ascii text
183+
if s.chars()
184+
.all(|c| matches!(c, '['..='~' | '0'..='9' | '('..='.' | '#'..='%'))
185+
{
188186
return Ok(Cow::Borrowed(s));
189187
}
190188

0 commit comments

Comments
 (0)