From 813a16c90c94eef4c4b7ef30a9221ea1329f6902 Mon Sep 17 00:00:00 2001 From: QuarticCat Date: Mon, 21 Nov 2022 17:22:19 +0800 Subject: [PATCH] Reduce branches of get_neighbours --- src/diff/graph.rs | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/diff/graph.rs b/src/diff/graph.rs index b769bb91cd..8e2d4eb5d9 100644 --- a/src/diff/graph.rs +++ b/src/diff/graph.rs @@ -430,9 +430,7 @@ pub fn get_neighbours<'syn, 'b>( v.pop_rhs_cnt, ), ); - } - - if let ( + } else if let ( Syntax::List { open_content: lhs_open_content, close_content: lhs_close_content, @@ -465,9 +463,7 @@ pub fn get_neighbours<'syn, 'b>( ), ); } - } - - if let ( + } else if let ( Syntax::Atom { content: lhs_content, kind: AtomKind::Comment, @@ -482,21 +478,19 @@ pub fn get_neighbours<'syn, 'b>( { // Both sides are comments and their content is reasonably // similar. - if lhs_content != rhs_content { - let levenshtein_pct = - (normalized_levenshtein(lhs_content, rhs_content) * 100.0).round() as u8; + let levenshtein_pct = + (normalized_levenshtein(lhs_content, rhs_content) * 100.0).round() as u8; - add_neighbor( - ReplacedComment { levenshtein_pct }, - next_vertex( - next_sibling(lhs_syntax), - next_sibling(rhs_syntax), - v.pop_both_ancestor, - v.pop_lhs_cnt, - v.pop_rhs_cnt, - ), - ); - } + add_neighbor( + ReplacedComment { levenshtein_pct }, + next_vertex( + next_sibling(lhs_syntax), + next_sibling(rhs_syntax), + v.pop_both_ancestor, + v.pop_lhs_cnt, + v.pop_rhs_cnt, + ), + ); } }