Skip to content

Commit 6b45a69

Browse files
authored
perf: bail early in too_many_lines lint if rule is not enabled. (#17605)
If the rule isn't enabled (which is the default behavior), there's no reason to scan the lines in the given function and count them. This avoids extra work for most users. changelog: none
2 parents eb12bac + e9bd6f2 commit 6b45a69

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

clippy_lints/src/functions/too_many_lines.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clippy_utils::diagnostics::span_lint;
2+
use clippy_utils::is_lint_allowed;
23
use clippy_utils::source::SpanExt as _;
34
use rustc_hir as hir;
45
use rustc_hir::def_id::LocalDefId;
@@ -22,6 +23,10 @@ pub(super) fn check_fn(
2223
return;
2324
}
2425

26+
if is_lint_allowed(cx, TOO_MANY_LINES, cx.tcx.local_def_id_to_hir_id(def_id)) {
27+
return;
28+
}
29+
2530
let mut line_count: u64 = 0;
2631
let too_many = body.value.span.check_text(cx, |src| {
2732
let mut in_comment = false;

0 commit comments

Comments
 (0)