From 9e2a5000d16a60aabcfa27033a6d28a76741a044 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 10 Dec 2021 00:27:12 +0100 Subject: [PATCH] Remove rayon and stdout lock --- Cargo.lock | 11 ----------- lychee-bin/src/commands/dump.rs | 12 ++++-------- lychee-lib/Cargo.toml | 2 -- lychee-lib/src/helpers/request.rs | 11 ++--------- 4 files changed, 6 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bbdd30eb33..b286bd1424 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -925,15 +925,6 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" -[[package]] -name = "ellipse" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1835a82a08e5c9393639e7cf99786a65af71f7fa9df7c91a519f2d52e6fa052d" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "encode_unicode" version = "0.3.6" @@ -1757,7 +1748,6 @@ dependencies = [ "cached", "check-if-email-exists", "doc-comment", - "ellipse", "fast_chemail", "futures", "glob", @@ -1774,7 +1764,6 @@ dependencies = [ "percent-encoding", "pretty_assertions", "pulldown-cmark", - "rayon", "regex", "reqwest", "ring", diff --git a/lychee-bin/src/commands/dump.rs b/lychee-bin/src/commands/dump.rs index da1b791d5b..eec1e80bbb 100644 --- a/lychee-bin/src/commands/dump.rs +++ b/lychee-bin/src/commands/dump.rs @@ -1,4 +1,4 @@ -use std::io::{self, StdoutLock, Write}; +use std::io::{self, Write}; use lychee_lib::Result; use lychee_lib::{Client, Request}; @@ -11,10 +11,6 @@ pub(crate) async fn dump<'a, S>(client: Client, requests: S, verbose: bool) -> R where S: futures::Stream>, { - // Lock stdout for better performance - let stdout = io::stdout(); - let mut handle = stdout.lock(); - tokio::pin!(requests); while let Some(request) = requests.next().await { @@ -28,7 +24,7 @@ where // See https://github.com/rust-lang/rust/issues/46016 // This can occur when piping the output of lychee // to another program like `grep`. - if let Err(e) = write(&mut handle, &request, verbose) { + if let Err(e) = write(&request, verbose) { if e.kind() != io::ErrorKind::BrokenPipe { eprintln!("{}", e); return Ok(ExitCode::UnexpectedFailure); @@ -42,11 +38,11 @@ where /// Dump request to stdout /// Only print source in verbose mode. This way the normal link output /// can be fed into another tool without data mangling. -fn write(handle: &mut StdoutLock<'_>, request: &Request, verbose: bool) -> io::Result<()> { +fn write(request: &Request, verbose: bool) -> io::Result<()> { let output = if verbose { request.to_string() } else { request.uri.to_string() }; - writeln!(*handle, "{}", output) + writeln!(io::stdout(), "{}", output) } diff --git a/lychee-lib/Cargo.toml b/lychee-lib/Cargo.toml index 9d514f7a48..37c5fe6807 100644 --- a/lychee-lib/Cargo.toml +++ b/lychee-lib/Cargo.toml @@ -47,8 +47,6 @@ cached = "0.26.2" once_cell = "1.8.0" thiserror = "1.0" futures = "0.3.18" -rayon = "1.5.1" -ellipse = "0.2.0" [dependencies.par-stream] version = "0.7.0" diff --git a/lychee-lib/src/helpers/request.rs b/lychee-lib/src/helpers/request.rs index c03210cc1e..827c28d000 100644 --- a/lychee-lib/src/helpers/request.rs +++ b/lychee-lib/src/helpers/request.rs @@ -1,8 +1,6 @@ -use ellipse::Ellipse; use html5ever::tendril::StrTendril; use log::info; use percent_encoding::percent_decode_str; -use rayon::iter::{IntoParallelIterator, ParallelIterator}; use reqwest::Url; use std::{ collections::HashSet, @@ -17,8 +15,6 @@ use crate::{ Base, ErrorKind, Input, Request, Result, Uri, }; -const MAX_SOURCE_LEN: usize = 100; - /// Create requests out of the collected URLs. /// Only keeps "valid" URLs. This filters out anchors for example. pub(crate) fn create( @@ -37,17 +33,14 @@ pub(crate) fn create( }; let requests: Result>> = uris - .into_par_iter() + .into_iter() .map(|raw_uri| { let is_anchor = raw_uri.is_anchor(); let text = StrTendril::from(raw_uri.text.clone()); let attribute = raw_uri.attribute.clone(); // Truncate the source in case it gets too long - let mut input = input_content.input.clone(); - if let Input::String(src) = input { - input = Input::String(src.as_str().truncate_ellipse(MAX_SOURCE_LEN).to_string()) - } + let input = input_content.input.clone(); if let Ok(uri) = Uri::try_from(raw_uri) { Ok(Some(Request::new(uri, input, attribute)))