From 6d849880d923f7a96c55e7440ceb0f9378b60f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Sat, 26 Jul 2025 00:51:39 +0200 Subject: [PATCH] parser: remove one indirection in `punction()` finding --- askama_parser/src/expr.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/askama_parser/src/expr.rs b/askama_parser/src/expr.rs index 4a40ffd1..63533a4f 100644 --- a/askama_parser/src/expr.rs +++ b/askama_parser/src/expr.rs @@ -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