|
| 1 | +use rayon::iter::{ParallelBridge, ParallelIterator}; |
1 | 2 | use std::env; |
2 | 3 | use std::path::Path; |
3 | 4 | use std::process::{Command, Output}; |
@@ -56,27 +57,30 @@ const DOCS_TO_CHECK: &[&str] = |
56 | 57 |
|
57 | 58 | // Returns the number of files read and the number of errors. |
58 | 59 | fn find_all_html_files(dir: &Path) -> (usize, usize) { |
59 | | - let mut files_read = 0; |
60 | | - let mut errors = 0; |
61 | | - |
62 | | - for entry in walkdir::WalkDir::new(dir).into_iter().filter_entry(|e| { |
63 | | - e.depth() != 1 |
64 | | - || e.file_name() |
65 | | - .to_str() |
66 | | - .map(|s| DOCS_TO_CHECK.into_iter().any(|d| *d == s)) |
67 | | - .unwrap_or(false) |
68 | | - }) { |
69 | | - let entry = entry.expect("failed to read file"); |
70 | | - if !entry.file_type().is_file() { |
71 | | - continue; |
72 | | - } |
73 | | - let entry = entry.path(); |
74 | | - if entry.extension().and_then(|s| s.to_str()) == Some("html") { |
75 | | - errors += check_html_file(&entry); |
76 | | - files_read += 1; |
77 | | - } |
78 | | - } |
79 | | - (files_read, errors) |
| 60 | + walkdir::WalkDir::new(dir) |
| 61 | + .into_iter() |
| 62 | + .filter_entry(|e| { |
| 63 | + e.depth() != 1 |
| 64 | + || e.file_name() |
| 65 | + .to_str() |
| 66 | + .map(|s| DOCS_TO_CHECK.into_iter().any(|d| *d == s)) |
| 67 | + .unwrap_or(false) |
| 68 | + }) |
| 69 | + .par_bridge() |
| 70 | + .map(|entry| { |
| 71 | + let entry = entry.expect("failed to read file"); |
| 72 | + if !entry.file_type().is_file() { |
| 73 | + return (0, 0); |
| 74 | + } |
| 75 | + let entry = entry.path(); |
| 76 | + // (Number of files processed, number of errors) |
| 77 | + if entry.extension().and_then(|s| s.to_str()) == Some("html") { |
| 78 | + (1, check_html_file(&entry)) |
| 79 | + } else { |
| 80 | + (0, 0) |
| 81 | + } |
| 82 | + }) |
| 83 | + .reduce(|| (0, 0), |a, b| (a.0 + b.0, a.1 + b.1)) |
80 | 84 | } |
81 | 85 |
|
82 | 86 | /// Default `tidy` command for macOS is too old that it does not have `mute-id` and `mute` options. |
|
0 commit comments