diff options
Diffstat (limited to 'support/pkgcheck/src/linkcheck.rs')
-rw-r--r-- | support/pkgcheck/src/linkcheck.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/support/pkgcheck/src/linkcheck.rs b/support/pkgcheck/src/linkcheck.rs index d7d1671dcf..cc7aa36e31 100644 --- a/support/pkgcheck/src/linkcheck.rs +++ b/support/pkgcheck/src/linkcheck.rs @@ -15,8 +15,7 @@ use std::sync::Mutex; use std::sync::atomic::Ordering; -use std::collections::HashMap; -use std::collections::HashSet; +use rustc_hash::{FxHashMap, FxHashSet}; enum UrlStatus { Unknown, @@ -25,11 +24,11 @@ enum UrlStatus { } struct HashVal { - paths: HashSet<String>, + paths: FxHashSet<String>, status: UrlStatus, } -type UrlHash = HashMap<String, HashVal>; +type UrlHash = FxHashMap<String, HashVal>; pub struct LinkCheck { pool: Mutex<ThreadPool>, @@ -43,7 +42,7 @@ impl LinkCheck { let pool = Mutex::new(ThreadPool::new(num_threads)); LinkCheck { pool, - urlhash: Arc::new(Mutex::new(HashMap::default())), + urlhash: Arc::new(Mutex::new(FxHashMap::default())), print_all, } } @@ -86,7 +85,7 @@ fn check_link(url: &str, fname: &str, urlhash: &Arc<Mutex<UrlHash>>, print_all: let mut urlhash = urlhash.lock().unwrap(); if !urlhash.contains_key(&url) { - let mut hs = HashSet::default(); + let mut hs = FxHashSet::default(); hs.insert(f); let url1 = url.clone(); @@ -166,6 +165,8 @@ fn get_links(fname: &str) -> Option<Vec<String>> { fn get_links_inner(s: &str) -> Option<Vec<String>> { let mut finder = LinkFinder::new(); finder.kinds(&[LinkKind::Url]); + + // finder.links() does the actual search for URLs let links: Vec<_> = finder.links(s).collect(); let result: Vec<&str> = links.iter().map(|e| e.as_str()).collect(); @@ -174,12 +175,11 @@ fn get_links_inner(s: &str) -> Option<Vec<String>> { if !r.starts_with("http://") && !r.starts_with("https://") && !r.starts_with("ftp://") { continue; } - // This is a workaround to prevent URLs ending with ` - if r.ends_with('`') { - links.push(String::from(&r[..r.len() - 1])); - } else { - links.push(String::from(r)); - } + + // This is a workaround to prevent URLs ending with certain characters + let url = r.trim_end_matches(|c| c == '。' || c == '`'); + + links.push(String::from(url)); } if !links.is_empty() { Some(links) |