Define a separate type for content IDs

split_more_thoroughly
Wilfred Hughes 2025-10-25 01:13:35 +07:00
parent 85c56e7a44
commit 020dd7d8dd
2 changed files with 8 additions and 6 deletions

@ -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<u32>) {
fn find_unique_content_ids(node: &Syntax, unique_ids: &mut DftHashSet<ContentId>) {
if node.content_is_unique() {
unique_ids.insert(node.content_id());
}

@ -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<u32>,
content_id: Cell<ContentId>,
/// Is this the only node with this content? Ignores nodes on the
/// other side.
content_is_unique: Cell<bool>,
@ -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<u32, usize>) {
fn find_nodes_with_unique_content(nodes: &[&Syntax], counts: &mut DftHashMap<ContentId, usize>) {
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<u32
}
}
fn set_content_is_unique_from_counts(nodes: &[&Syntax], counts: &DftHashMap<u32, usize>) {
fn set_content_is_unique_from_counts(nodes: &[&Syntax], counts: &DftHashMap<ContentId, usize>) {
for node in nodes {
let count = counts
.get(&node.content_id())