From c4d1a639b02e511707e1af99a99743d25ddde075 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 20 Nov 2021 10:01:14 +0000 Subject: [PATCH] Remove itertools dependency Collecting into Vec of &str and joining may even be faster according to benchmarks: https://gist.github.com/green-s/fbd0d374b290781ac9b3f8ff03e3245d --- Cargo.lock | 1 - Cargo.toml | 1 - src/chat.rs | 3 +-- src/configure.rs | 7 +++++-- src/contact.rs | 13 +++++-------- src/dc_receive_imf.rs | 13 ++++++++++--- src/job.rs | 3 +-- src/param.rs | 3 +-- src/simplify.rs | 4 ++-- src/smtp/send.rs | 11 +++++++---- src/summary.rs | 3 +-- src/sync.rs | 6 ++++-- 12 files changed, 37 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6a5a8608a..3a7bdb053 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1101,7 +1101,6 @@ dependencies = [ "humansize", "image", "indexmap", - "itertools", "kamadak-exif", "lettre_email", "libc", diff --git a/Cargo.toml b/Cargo.toml index 9226c29f0..b906e782e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,6 @@ futures = "0.3" hex = "0.4.0" image = { version = "0.23.5", default-features=false, features = ["gif", "jpeg", "ico", "png", "pnm", "webp", "bmp"] } indexmap = "1.7" -itertools = "0.10" kamadak-exif = "0.5" lettre_email = { git = "https://github.com/deltachat/lettre", branch = "master" } libc = "0.2" diff --git a/src/chat.rs b/src/chat.rs index 5eeb6e770..aaff1a695 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -7,7 +7,6 @@ use std::time::{Duration, SystemTime}; use anyhow::{bail, ensure, format_err, Context as _, Result}; use async_std::path::{Path, PathBuf}; use deltachat_derive::{FromSql, ToSql}; -use itertools::Itertools; use serde::{Deserialize, Serialize}; use crate::aheader::EncryptPreference; @@ -2817,7 +2816,7 @@ pub async fn forward_msgs(context: &Context, msg_ids: &[MsgId], chat_id: ChatId) .query_map( format!( "SELECT id FROM msgs WHERE id IN({}) ORDER BY timestamp,id", - msg_ids.iter().map(|_| "?").join(",") + msg_ids.iter().map(|_| "?").collect::>().join(",") ), rusqlite::params_from_iter(msg_ids), |row| row.get::<_, MsgId>(0), diff --git a/src/configure.rs b/src/configure.rs index e9ff4dab6..7b04dd9e8 100644 --- a/src/configure.rs +++ b/src/configure.rs @@ -8,7 +8,6 @@ mod server_params; use anyhow::{bail, ensure, Context as _, Result}; use async_std::prelude::*; use async_std::task; -use itertools::Itertools; use job::Action; use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC}; @@ -682,7 +681,11 @@ async fn nicer_configuration_error(context: &Context, errors: Vec>() + .join("\n\n") } #[derive(Debug, thiserror::Error)] diff --git a/src/contact.rs b/src/contact.rs index 3d467a395..10b88e2e5 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -5,7 +5,6 @@ use std::convert::{TryFrom, TryInto}; use anyhow::{bail, ensure, Context as _, Result}; use async_std::path::PathBuf; use deltachat_derive::{FromSql, ToSql}; -use itertools::Itertools; use once_cell::sync::Lazy; use regex::Regex; @@ -1356,15 +1355,13 @@ pub fn addr_cmp(addr1: impl AsRef, addr2: impl AsRef) -> bool { fn split_address_book(book: &str) -> Vec<(&str, &str)> { book.lines() + .collect::>() .chunks(2) .into_iter() - .filter_map(|mut chunk| { - let name = chunk.next().unwrap(); - let addr = match chunk.next() { - Some(a) => a, - None => return None, - }; - Some((name, addr)) + .filter_map(|chunk| { + let name = chunk.get(0)?; + let addr = chunk.get(1)?; + Some((*name, *addr)) }) .collect() } diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index c0ab3ef2a..be4cebec9 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -4,7 +4,6 @@ use std::cmp::min; use std::convert::TryFrom; use anyhow::{bail, ensure, Context as _, Result}; -use itertools::join; use mailparse::SingleInfo; use num_traits::FromPrimitive; use once_cell::sync::Lazy; @@ -1931,7 +1930,11 @@ async fn create_adhoc_group( /// are hidden in BCC. This group ID is sent by DC in the messages sent to this chat, /// so having the same ID prevents group split. async fn create_adhoc_grp_id(context: &Context, member_ids: &[u32]) -> Result { - let member_ids_str = join(member_ids.iter().map(|x| x.to_string()), ","); + let member_ids_str = member_ids + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(","); let member_cs = context .get_config(Config::ConfiguredAddr) .await? @@ -2023,7 +2026,11 @@ async fn check_verified_properties( if to_ids.is_empty() { return Ok(()); } - let to_ids_str = join(to_ids.iter().map(|x| x.to_string()), ","); + let to_ids_str = to_ids + .iter() + .map(|x| x.to_string()) + .collect::>() + .join(","); let rows = context .sql diff --git a/src/job.rs b/src/job.rs index 0e579813e..81b051c90 100644 --- a/src/job.rs +++ b/src/job.rs @@ -8,7 +8,6 @@ use std::future::Future; use anyhow::{bail, ensure, format_err, Context as _, Error, Result}; use async_smtp::smtp::response::{Category, Code, Detail}; use deltachat_derive::{FromSql, ToSql}; -use itertools::Itertools; use rand::{thread_rng, Rng}; use crate::blob::BlobObject; @@ -840,7 +839,7 @@ pub async fn kill_action(context: &Context, action: Action) -> Result<()> { async fn kill_ids(context: &Context, job_ids: &[u32]) -> Result<()> { let q = format!( "DELETE FROM jobs WHERE id IN({})", - job_ids.iter().map(|_| "?").join(",") + job_ids.iter().map(|_| "?").collect::>().join(",") ); context .sql diff --git a/src/param.rs b/src/param.rs index cecc36911..9d52c4445 100644 --- a/src/param.rs +++ b/src/param.rs @@ -4,7 +4,6 @@ use std::str; use anyhow::{bail, Error}; use async_std::path::PathBuf; -use itertools::Itertools; use num_traits::FromPrimitive; use serde::{Deserialize, Serialize}; @@ -182,7 +181,7 @@ impl fmt::Display for Params { f, "{}={}", *key as u8 as char, - value.split('\n').join("\n\n") + value.split('\n').collect::>().join("\n\n") )?; } Ok(()) diff --git a/src/simplify.rs b/src/simplify.rs index faa3b76f5..06f6bc37d 100644 --- a/src/simplify.rs +++ b/src/simplify.rs @@ -1,7 +1,5 @@ //! # Simplify incoming plaintext. -use itertools::Itertools; - // protect lines starting with `--` against being treated as a footer. // for that, we insert a ZERO WIDTH SPACE (ZWSP, 0x200B); // this should be invisible on most systems and there is no need to unescape it again @@ -158,6 +156,7 @@ fn remove_bottom_quote<'a>(lines: &'a [&str]) -> (&'a [&'a str], Option) s.strip_prefix('>') .map_or(*s, |u| u.strip_prefix(' ').unwrap_or(u)) }) + .collect::>() .join("\n"); if l_last > 1 && is_empty_line(lines[l_last - 1]) { l_last -= 1 @@ -204,6 +203,7 @@ fn remove_top_quote<'a>(lines: &'a [&str]) -> (&'a [&'a str], Option) { s.strip_prefix('>') .map_or(*s, |u| u.strip_prefix(' ').unwrap_or(u)) }) + .collect::>() .join("\n"), ), ) diff --git a/src/smtp/send.rs b/src/smtp/send.rs index fe1e813a7..40b8681d9 100644 --- a/src/smtp/send.rs +++ b/src/smtp/send.rs @@ -6,7 +6,6 @@ use async_smtp::{EmailAddress, Envelope, SendableEmail, Transport}; use crate::constants::DEFAULT_MAX_SMTP_RCPT_TO; use crate::context::Context; use crate::events::EventType; -use itertools::Itertools; use std::time::Duration; pub type Result = std::result::Result; @@ -43,10 +42,14 @@ impl Smtp { } for recipients_chunk in recipients.chunks(chunk_size).into_iter() { - let recipients = recipients_chunk.to_vec(); - let recipients_display = recipients.iter().map(|x| x.to_string()).join(","); + let recipients_display = recipients_chunk + .iter() + .map(|x| x.as_ref()) + .collect::>() + .join(","); - let envelope = Envelope::new(self.from.clone(), recipients).map_err(Error::Envelope)?; + let envelope = Envelope::new(self.from.clone(), recipients_chunk.to_vec()) + .map_err(Error::Envelope)?; let mail = SendableEmail::new( envelope, format!("{}", job_id), // only used for internal logging diff --git a/src/summary.rs b/src/summary.rs index fc6adc2d4..6c590ff0e 100644 --- a/src/summary.rs +++ b/src/summary.rs @@ -9,7 +9,6 @@ use crate::message::{Message, MessageState}; use crate::mimeparser::SystemMessage; use crate::param::Param; use crate::stock_str; -use itertools::Itertools; use std::borrow::Cow; use std::fmt; @@ -174,7 +173,7 @@ impl Message { summary_content }; - summary.split_whitespace().join(" ") + summary.split_whitespace().collect::>().join(" ") } } diff --git a/src/sync.rs b/src/sync.rs index cddb0fc34..3054f4a70 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -12,7 +12,6 @@ use crate::sync::SyncData::{AddQrToken, DeleteQrToken}; use crate::token::Namespace; use crate::{chat, stock_str, token}; use anyhow::Result; -use itertools::Itertools; use lettre_email::mime::{self}; use lettre_email::PartBuilder; use serde::{Deserialize, Serialize}; @@ -177,7 +176,10 @@ impl Context { } else { Ok(Some(( format!("{{\"items\":[\n{}\n]}}", serialized), - ids.iter().map(|x| x.to_string()).join(","), + ids.iter() + .map(|x| x.to_string()) + .collect::>() + .join(","), ))) } }