From c310fb34f99a148faad5858db5dce1b6dba62a89 Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Sun, 8 Jan 2023 21:34:49 -0800 Subject: [PATCH] Use u32 for edge cost This is performance neutral (both runtime and memory size) but the code is slightly readable as there are fewer conversions. --- src/diff/graph.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/diff/graph.rs b/src/diff/graph.rs index 63e22d500..b7b9e149b 100644 --- a/src/diff/graph.rs +++ b/src/diff/graph.rs @@ -50,7 +50,7 @@ use Edge::*; #[derive(Debug, Clone)] pub struct Vertex<'a, 'b> { pub neighbours: RefCell)>>>, - pub predecessor: Cell)>>, + pub predecessor: Cell)>>, pub lhs_syntax: Option<&'a Syntax<'a>>, pub rhs_syntax: Option<&'a Syntax<'a>>, parents: Stack>, @@ -299,20 +299,18 @@ pub enum Edge { }, } -const NOT_CONTIGUOUS_PENALTY: u64 = 50; +const NOT_CONTIGUOUS_PENALTY: u32 = 50; impl Edge { - pub fn cost(self) -> u64 { + pub fn cost(self) -> u32 { match self { // Matching nodes is always best. - UnchangedNode { depth_difference } => min(40, u64::from(depth_difference) + 1), + UnchangedNode { depth_difference } => min(40, depth_difference + 1), // Matching an outer delimiter is good. - EnterUnchangedDelimiter { depth_difference } => { - 100 + min(40, u64::from(depth_difference)) - } + EnterUnchangedDelimiter { depth_difference } => 100 + min(40, depth_difference), // Replacing a comment is better than treating it as novel. - ReplacedComment { levenshtein_pct } => 150 + u64::from(100 - levenshtein_pct), + ReplacedComment { levenshtein_pct } => 150 + u32::from(100 - levenshtein_pct), // Otherwise, we've added/removed a node. NovelAtomLHS {