1
Fork 0

Refactor disallowed_script_idents: Simplify script checking loop.

This commit is contained in:
Jason Newcomb 2024-06-09 22:19:35 -04:00
parent d2400a49a4
commit ac939ad3a1

View file

@ -82,18 +82,16 @@ impl EarlyLintPass for DisallowedScriptIdents {
// Note: `symbol.as_str()` is an expensive operation, thus should not be called // Note: `symbol.as_str()` is an expensive operation, thus should not be called
// more than once for a single symbol. // more than once for a single symbol.
let symbol_str = symbol.as_str(); let symbol_str = symbol.as_str();
if symbol_str.is_ascii() {
continue;
}
for c in symbol_str.chars() { // Check if any character in the symbol is not part of any allowed script.
// We want to iterate through all the scripts associated with this character // Fast path for ascii-only idents.
// and check whether at least of one scripts is in the whitelist. if !symbol_str.is_ascii()
let forbidden_script = c && let Some(script) = symbol_str.chars().find_map(|c| {
.script_extension() c.script_extension()
.iter() .iter()
.find(|script| !self.whitelist.contains(script)); .find(|script| !self.whitelist.contains(script))
if let Some(script) = forbidden_script { })
{
span_lint( span_lint(
cx, cx,
DISALLOWED_SCRIPT_IDENTS, DISALLOWED_SCRIPT_IDENTS,
@ -103,9 +101,6 @@ impl EarlyLintPass for DisallowedScriptIdents {
script.full_name() script.full_name()
), ),
); );
// We don't want to spawn warning multiple times over a single identifier.
break;
}
} }
} }
} }