From 020dd7d8dd697ec19a9da470b0357ffd5f194f7f Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Sat, 25 Oct 2025 01:13:35 +0100 Subject: [PATCH] Define a separate type for content IDs --- src/diff/unchanged.rs | 4 ++-- src/parse/syntax.rs | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/diff/unchanged.rs b/src/diff/unchanged.rs index 359ba5778..181b34966 100644 --- a/src/diff/unchanged.rs +++ b/src/diff/unchanged.rs @@ -6,7 +6,7 @@ use std::hash::Hash; use crate::diff::changes::{insert_deep_unchanged, ChangeKind, ChangeMap}; use crate::diff::lcs_diff; use crate::hash::DftHashSet; -use crate::parse::syntax::Syntax; +use crate::parse::syntax::{ContentId, Syntax}; const TINY_TREE_THRESHOLD: u32 = 10; const MOSTLY_UNCHANGED_MIN_COMMON_CHILDREN: usize = 4; @@ -123,7 +123,7 @@ fn split_unchanged_singleton_list<'a>( res } -fn find_unique_content_ids(node: &Syntax, unique_ids: &mut DftHashSet) { +fn find_unique_content_ids(node: &Syntax, unique_ids: &mut DftHashSet) { if node.content_is_unique() { unique_ids.insert(node.content_id()); } diff --git a/src/parse/syntax.rs b/src/parse/syntax.rs index 7dbec3187..8e3bb445a 100644 --- a/src/parse/syntax.rs +++ b/src/parse/syntax.rs @@ -48,6 +48,8 @@ impl fmt::Debug for ChangeKind<'_> { pub(crate) type SyntaxId = NonZeroU32; +pub(crate) type ContentId = u32; + /// Fields that are common to both `Syntax::List` and `Syntax::Atom`. pub(crate) struct SyntaxInfo<'a> { /// The previous node with the same parent as this one. @@ -69,7 +71,7 @@ pub(crate) struct SyntaxInfo<'a> { /// diff, or nodes at different positions. /// /// Values are sequential, not hashes. Collisions never occur. - content_id: Cell, + content_id: Cell, /// Is this the only node with this content? Ignores nodes on the /// other side. content_is_unique: Cell, @@ -298,7 +300,7 @@ impl<'a> Syntax<'a> { /// A content ID of this syntax node. Two nodes have the same /// content ID if they have the same content, regardless of /// position. - pub(crate) fn content_id(&self) -> u32 { + pub(crate) fn content_id(&self) -> ContentId { self.info().content_id.get() } @@ -507,7 +509,7 @@ fn set_unique_id(nodes: &[&Syntax], next_id: &mut SyntaxId) { } /// Assumes that `set_content_id` has already run. -fn find_nodes_with_unique_content(nodes: &[&Syntax], counts: &mut DftHashMap) { +fn find_nodes_with_unique_content(nodes: &[&Syntax], counts: &mut DftHashMap) { for node in nodes { *counts.entry(node.content_id()).or_insert(0) += 1; if let List { children, .. } = node { @@ -516,7 +518,7 @@ fn find_nodes_with_unique_content(nodes: &[&Syntax], counts: &mut DftHashMap) { +fn set_content_is_unique_from_counts(nodes: &[&Syntax], counts: &DftHashMap) { for node in nodes { let count = counts .get(&node.content_id())