diff options
| author | blyxyas <blyxyas@gmail.com> | 2025-08-02 01:57:57 +0200 |
|---|---|---|
| committer | blyxyas <blyxyas@gmail.com> | 2025-08-02 01:59:48 +0200 |
| commit | 01d960f645b3f1e47a79ea925f9e04a5bfbbd769 (patch) | |
| tree | c65aa58307c5307a3e75c5ee02bf12f807314c15 | |
| parent | 94b703588e1da6b7492375575da92c2859a3c39b (diff) | |
| download | rust-01d960f645b3f1e47a79ea925f9e04a5bfbbd769.tar.gz rust-01d960f645b3f1e47a79ea925f9e04a5bfbbd769.zip | |
Optimize broken_links by 99.77%
| -rw-r--r-- | clippy_lints/src/doc/broken_link.rs | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/clippy_lints/src/doc/broken_link.rs b/clippy_lints/src/doc/broken_link.rs index 4af10510023..8878fa9180f 100644 --- a/clippy_lints/src/doc/broken_link.rs +++ b/clippy_lints/src/doc/broken_link.rs @@ -19,52 +19,52 @@ pub fn check(cx: &LateContext<'_>, bl: &PullDownBrokenLink<'_>, doc: &str, fragm } fn warn_if_broken_link(cx: &LateContext<'_>, bl: &PullDownBrokenLink<'_>, doc: &str, fragments: &[DocFragment]) { - if let Some((span, _)) = source_span_for_markdown_range(cx.tcx, doc, &bl.span, fragments) { - let mut len = 0; + let mut len = 0; - // grab raw link data - let (_, raw_link) = doc.split_at(bl.span.start); + // grab raw link data + let (_, raw_link) = doc.split_at(bl.span.start); - // strip off link text part - let raw_link = match raw_link.split_once(']') { - None => return, - Some((prefix, suffix)) => { - len += prefix.len() + 1; - suffix - }, - }; + // strip off link text part + let raw_link = match raw_link.split_once(']') { + None => return, + Some((prefix, suffix)) => { + len += prefix.len() + 1; + suffix + }, + }; - let raw_link = match raw_link.split_once('(') { - None => return, - Some((prefix, suffix)) => { - if !prefix.is_empty() { - // there is text between ']' and '(' chars, so it is not a valid link - return; - } - len += prefix.len() + 1; - suffix - }, - }; - - if raw_link.starts_with("(http") { - // reduce chances of false positive reports - // by limiting this checking only to http/https links. - return; - } - - for c in raw_link.chars() { - if c == ')' { - // it is a valid link + let raw_link = match raw_link.split_once('(') { + None => return, + Some((prefix, suffix)) => { + if !prefix.is_empty() { + // there is text between ']' and '(' chars, so it is not a valid link return; } + len += prefix.len() + 1; + suffix + }, + }; - if c == '\n' { - report_broken_link(cx, span, len); - break; - } + if raw_link.starts_with("(http") { + // reduce chances of false positive reports + // by limiting this checking only to http/https links. + return; + } - len += 1; + for c in raw_link.chars() { + if c == ')' { + // it is a valid link + return; } + + if c == '\n' + && let Some((span, _)) = source_span_for_markdown_range(cx.tcx, doc, &bl.span, fragments) + { + report_broken_link(cx, span, len); + break; + } + + len += 1; } } |
