Merge pull request #543 from Kijewski/143907

parser: remove one indirection in `punction()` finding
This commit is contained in:
Guillaume Gomez 2025-07-28 17:30:57 +02:00 committed by GitHub
commit 11da13eeb8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1035,18 +1035,21 @@ impl<'a> Suffix<'a> {
// hash '#' omitted
const ONE_CHAR: &[u8] = b"+-*/%^!&|=><@_.,;:$?~";
const TWO_CHARS: &[&str] = &[
"&&", "||", "<<", ">>", "+=", "-=", "*=", "/=", "%=", "^=", "&=", "|=", "==", "!=",
">=", "<=", "..", "::", "->", "=>", "<-",
const TWO_CHARS: &[[u8; 2]] = &[
*b"&&", *b"||", *b"<<", *b">>", *b"+=", *b"-=", *b"*=", *b"/=", *b"%=", *b"^=",
*b"&=", *b"|=", *b"==", *b"!=", *b">=", *b"<=", *b"..", *b"::", *b"->", *b"=>",
*b"<-",
];
const THREE_CHARS: &[&str] = &["<<=", ">>=", "...", "..="];
const THREE_CHARS: &[[u8; 3]] = &[*b"<<=", *b">>=", *b"...", *b"..="];
// need to check long to short
*i = if let Some((head, tail)) = i.split_at_checked(3)
&& THREE_CHARS.contains(&head)
&& let Ok(head) = head.as_bytes().try_into()
&& THREE_CHARS.contains(head)
{
tail
} else if let Some((head, tail)) = i.split_at_checked(2)
&& let Ok(head) = head.as_bytes().try_into()
&& TWO_CHARS.contains(&head)
{
tail