Avoid allocation in no-signature (#6375)

This commit is contained in:
Charlie Marsh 2023-08-06 11:27:56 -04:00 committed by GitHub
parent a5a29bb8d6
commit 9171e97d15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -72,11 +72,14 @@ pub(crate) fn no_signature(checker: &mut Checker, docstring: &Docstring) {
return;
};
if !first_line.contains(&format!("{name}(")) {
return;
};
checker
.diagnostics
.push(Diagnostic::new(NoSignature, docstring.range()));
// Search for occurrences of the function name followed by an open parenthesis (e.g., `foo(` for
// a function named `foo`).
if first_line
.match_indices(name.as_str())
.any(|(index, _)| first_line[index + name.len()..].starts_with('('))
{
checker
.diagnostics
.push(Diagnostic::new(NoSignature, docstring.range()));
}
}