From ed7ceebfe07c674933b002beda88391ad5cd6066 Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Sat, 7 Oct 2017 22:17:01 +0900 Subject: [PATCH] Faster last_line_extendable() --- src/utils.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 649a6070fd2..3106df9ed8b 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -171,12 +171,18 @@ pub fn trimmed_last_line_width(s: &str) -> usize { #[inline] pub fn last_line_extendable(s: &str) -> bool { - s.lines().last().map_or(false, |s| { - s.ends_with("\"#") - || s.trim() - .chars() - .all(|c| c == ')' || c == ']' || c == '}' || c == '?') - }) + if s.ends_with("\"#") { + return true; + } + for c in s.chars().rev() { + match c { + ')' | ']' | '}' | '?' => continue, + '\n' => break, + _ if c.is_whitespace() => continue, + _ => return false, + } + } + true } #[inline] -- 2.44.0