From 80bd23fd112b7ab0efbb02ca278cb75d02dcd195 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Fri, 16 Feb 2024 11:04:42 +0100 Subject: [PATCH] chore(lib): rewrite using ClassUnicode methods As suggested by @RustyYato --- logos-codegen/src/graph/regex.rs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/logos-codegen/src/graph/regex.rs b/logos-codegen/src/graph/regex.rs index 40aa1c02..a1c2ffe7 100644 --- a/logos-codegen/src/graph/regex.rs +++ b/logos-codegen/src/graph/regex.rs @@ -160,25 +160,15 @@ impl Graph { } } +#[inline] fn is_ascii(class: &ClassUnicode) -> bool { - class.iter().all(|range| { - let start = range.start() as u32; - let end = range.end() as u32; - - start < 128 && end < 128 - }) + class.is_ascii() } +#[inline] fn is_one_ascii(class: &ClassUnicode) -> bool { - if class.ranges().len() != 1 { - return false; - } - - let range = &class.ranges()[0]; - let start = range.start() as u32; - let end = range.end() as u32; - - start < 128 && end < 128 + let ranges = class.ranges(); + ranges.len() == 1 && ranges[0].end() < '\x7F' } #[cfg(test)]