From 66e71dafb883c3009b1938f504554cdaab687256 Mon Sep 17 00:00:00 2001 From: Hatano Yuusuke <56590357+kynthus@users.noreply.github.com> Date: Tue, 8 Jun 2021 17:50:21 +0900 Subject: [PATCH] Don't use trim() and unnecessary lazy evaluation --- src/preprocess/links.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/preprocess/links.rs b/src/preprocess/links.rs index 52c8791b..e59e34fc 100644 --- a/src/preprocess/links.rs +++ b/src/preprocess/links.rs @@ -103,9 +103,11 @@ where .ok() .map(|bol| (bol, mt.start(), mt.end())) }) - .map(|(bol, st, ed)| bol.replace_all(new_content.as_str(), &s[st..ed])) - .map(|cow| String::from(cow.trim())) - .unwrap_or_else(|| new_content); + .map(|(bol, st, ed)| { + (bol.replace_all(new_content.as_str(), &s[st..ed]), ed - st) + }) + .map(|(cow, skip)| String::from(&cow[skip..])) + .unwrap_or(new_content); if depth < MAX_LINK_NESTED_DEPTH { if let Some(rel_path) = link.link_type.relative_path(path) {