mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 05:51:39 +00:00
Refactor ChangeBatcher tests to remove skipped count checks
- Updated the `encodeInstance.stress.spec.lua` tests to eliminate checks for skipped counts, as duplicates are now included alongside unique children. - Adjusted expectations in the tests to reflect the new behavior of the encoding process, ensuring accurate validation of encoded instances. - Removed legacy assertions related to skipped counts, streamlining the test cases for better clarity and maintainability.
This commit is contained in:
parent
d6162ac210
commit
e313f61515
7 changed files with 53 additions and 132 deletions
|
|
@ -51,79 +51,6 @@ pub fn collect_all_paths(dom: &WeakDom) -> HashMap<Ref, String> {
|
|||
paths
|
||||
}
|
||||
|
||||
/// Pre-computes which instances have duplicate-named siblings.
|
||||
/// Returns a HashSet of Refs that have at least one sibling with the same name.
|
||||
///
|
||||
/// This is O(N) where N is the number of instances, and allows subsequent
|
||||
/// path uniqueness checks to be O(d) instead of O(d × s) where d=depth, s=siblings.
|
||||
fn compute_refs_with_duplicate_siblings(dom: &WeakDom) -> HashSet<Ref> {
|
||||
let mut has_duplicate_siblings = HashSet::new();
|
||||
let mut queue = VecDeque::new();
|
||||
queue.push_back(dom.root_ref());
|
||||
|
||||
while let Some(inst_ref) = queue.pop_front() {
|
||||
let inst = match dom.get_by_ref(inst_ref) {
|
||||
Some(i) => i,
|
||||
None => continue,
|
||||
};
|
||||
|
||||
// Count children by name and collect their refs
|
||||
let mut name_to_refs: HashMap<&str, Vec<Ref>> = HashMap::new();
|
||||
for child_ref in inst.children() {
|
||||
if let Some(child) = dom.get_by_ref(*child_ref) {
|
||||
name_to_refs
|
||||
.entry(&child.name)
|
||||
.or_default()
|
||||
.push(*child_ref);
|
||||
}
|
||||
queue.push_back(*child_ref);
|
||||
}
|
||||
|
||||
// Mark refs that share a name with siblings
|
||||
for (_name, refs) in name_to_refs {
|
||||
if refs.len() > 1 {
|
||||
for r in refs {
|
||||
has_duplicate_siblings.insert(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
has_duplicate_siblings
|
||||
}
|
||||
|
||||
/// Checks if a path is unique using pre-computed duplicate sibling info.
|
||||
/// This is O(d) where d is the depth of the instance.
|
||||
fn is_path_unique_with_cache(
|
||||
dom: &WeakDom,
|
||||
target_ref: Ref,
|
||||
has_duplicate_siblings: &HashSet<Ref>,
|
||||
) -> bool {
|
||||
let mut current_ref = target_ref;
|
||||
|
||||
// Walk up the tree checking each level using the pre-computed cache
|
||||
loop {
|
||||
// O(1) lookup instead of O(siblings) counting
|
||||
if has_duplicate_siblings.contains(¤t_ref) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let current = match dom.get_by_ref(current_ref) {
|
||||
Some(inst) => inst,
|
||||
None => return false,
|
||||
};
|
||||
|
||||
let parent_ref = current.parent();
|
||||
if parent_ref.is_none() {
|
||||
// Reached root - path is unique at all levels
|
||||
return true;
|
||||
}
|
||||
|
||||
// Move up to parent and check the next level
|
||||
current_ref = parent_ref;
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterates through a WeakDom and collects referent properties.
|
||||
/// Uses paths when unique, falls back to IDs when paths are ambiguous.
|
||||
///
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue