Skip to content

Commit 97037b8

Browse files
committed
perf: skip the NFC scan for all-ASCII literals in unicode lints
1 parent 824aa1f commit 97037b8

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

clippy_lints/src/unicode.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ fn check_str(cx: &LateContext<'_>, span: Span, id: HirId) {
108108
}
109109

110110
let string = snippet(cx, span, "");
111+
// An all-ASCII snippet has no invisible char, non-ASCII char, or non-NFC sequence,
112+
// so none of the lints below can fire: skip the expensive NFC scan in that common case.
113+
if string.is_ascii() {
114+
return;
115+
}
111116
if string.chars().any(|c| ['\u{200B}', '\u{ad}', '\u{2060}'].contains(&c)) {
112117
#[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")]
113118
span_lint_and_then(cx, INVISIBLE_CHARACTERS, span, "invisible character detected", |diag| {

0 commit comments

Comments
 (0)