mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-25 04:54:07 +00:00
Refactor matching logic for improved readability and consistency
- Simplified function calls in `Reconciler/matching.lua` by consolidating multi-line arguments into single lines, enhancing code clarity. - Updated `matching.rs` to improve formatting of method calls and assertions, ensuring a more consistent style throughout the test suite. - Enhanced the `matching_fixtures.rs` file by streamlining the loading of input data and improving the readability of child copying logic. These changes contribute to a cleaner and more maintainable codebase, facilitating easier future modifications.
This commit is contained in:
parent
21b3ee45fd
commit
6ef81cf8e0
3 changed files with 28 additions and 40 deletions
|
|
@ -301,9 +301,7 @@ function Matching._computeChildrenCost(
|
||||||
|
|
||||||
local cost = 0
|
local cost = 0
|
||||||
for _, pair in childResult.matched do
|
for _, pair in childResult.matched do
|
||||||
cost += Matching._computeChangeCount(
|
cost += Matching._computeChangeCount(pair.virtualId, pair.studioInstance, virtualInstances, bestSoFar - cost)
|
||||||
pair.virtualId, pair.studioInstance, virtualInstances, bestSoFar - cost
|
|
||||||
)
|
|
||||||
if cost >= bestSoFar then
|
if cost >= bestSoFar then
|
||||||
return cost
|
return cost
|
||||||
end
|
end
|
||||||
|
|
@ -527,9 +525,7 @@ function Matching.matchChildren(
|
||||||
local sCaches: { [number]: any } = {}
|
local sCaches: { [number]: any } = {}
|
||||||
for _, si in sIndices do
|
for _, si in sIndices do
|
||||||
if not matchedS2[si] then
|
if not matchedS2[si] then
|
||||||
sCaches[si] = Matching._cacheStudio(
|
sCaches[si] = Matching._cacheStudio(remainingStudio[si], classKeys, extraPropNamesArray)
|
||||||
remainingStudio[si], classKeys, extraPropNamesArray
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -569,9 +565,7 @@ function Matching.matchChildren(
|
||||||
-- Recursive children cost
|
-- Recursive children cost
|
||||||
local vInst = virtualInstances[remainingVirtual[vi]]
|
local vInst = virtualInstances[remainingVirtual[vi]]
|
||||||
if vInst then
|
if vInst then
|
||||||
cost += Matching._computeChildrenCost(
|
cost += Matching._computeChildrenCost(vInst, sCache, virtualInstances, bestSoFar - cost)
|
||||||
vInst, sCache, virtualInstances, bestSoFar - cost
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -772,7 +772,10 @@ mod tests {
|
||||||
use rbx_dom_weak::types::Variant;
|
use rbx_dom_weak::types::Variant;
|
||||||
|
|
||||||
let db = rbx_reflection_database::get().expect("reflection database should load");
|
let db = rbx_reflection_database::get().expect("reflection database should load");
|
||||||
let texture = db.classes.get("Texture").expect("Texture class should exist");
|
let texture = db
|
||||||
|
.classes
|
||||||
|
.get("Texture")
|
||||||
|
.expect("Texture class should exist");
|
||||||
let face_default = texture
|
let face_default = texture
|
||||||
.default_properties
|
.default_properties
|
||||||
.get("Face")
|
.get("Face")
|
||||||
|
|
@ -842,15 +845,11 @@ mod tests {
|
||||||
make_snapshot_with_props("Texture", "Texture", props)
|
make_snapshot_with_props("Texture", "Texture", props)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
tree_children.push(make_snapshot_with_props(
|
tree_children.push(make_snapshot_with_props("Texture", "Texture", {
|
||||||
"Texture",
|
|
||||||
"Texture",
|
|
||||||
{
|
|
||||||
let mut props = shared_props.clone();
|
let mut props = shared_props.clone();
|
||||||
props.push(("Face", Variant::Enum(face_front.clone())));
|
props.push(("Face", Variant::Enum(face_front.clone())));
|
||||||
props
|
props
|
||||||
},
|
}));
|
||||||
));
|
|
||||||
|
|
||||||
let (tree, tree_refs) = make_tree_from_snapshots(tree_children);
|
let (tree, tree_refs) = make_tree_from_snapshots(tree_children);
|
||||||
let result = match_forward(snaps, &tree_refs, &tree);
|
let result = match_forward(snaps, &tree_refs, &tree);
|
||||||
|
|
@ -1132,11 +1131,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
snaps.push(make_snapshot_with_props("Texture", "Texture", snap_props));
|
snaps.push(make_snapshot_with_props("Texture", "Texture", snap_props));
|
||||||
tree_children.push(make_snapshot_with_props(
|
tree_children.push(make_snapshot_with_props("Texture", "Texture", tree_props));
|
||||||
"Texture",
|
|
||||||
"Texture",
|
|
||||||
tree_props,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,8 @@ fn load_input_rbxm() -> WeakDom {
|
||||||
let path = Path::new(SYNCBACK_TESTS_PATH)
|
let path = Path::new(SYNCBACK_TESTS_PATH)
|
||||||
.join(FIXTURE_DIR)
|
.join(FIXTURE_DIR)
|
||||||
.join("input.rbxm");
|
.join("input.rbxm");
|
||||||
let data = std::fs::read(&path).unwrap_or_else(|e| panic!("Failed to read {}: {}", path.display(), e));
|
let data =
|
||||||
|
std::fs::read(&path).unwrap_or_else(|e| panic!("Failed to read {}: {}", path.display(), e));
|
||||||
rbx_binary::from_reader(data.as_slice())
|
rbx_binary::from_reader(data.as_slice())
|
||||||
.unwrap_or_else(|e| panic!("Failed to parse {}: {}", path.display(), e))
|
.unwrap_or_else(|e| panic!("Failed to parse {}: {}", path.display(), e))
|
||||||
}
|
}
|
||||||
|
|
@ -69,12 +70,13 @@ fn rojo_tree_to_weak_dom(tree: &librojo::RojoTree) -> WeakDom {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recursively copy children
|
// Recursively copy children
|
||||||
fn copy_children(tree: &librojo::RojoTree, parent_ref: Ref, dom: &mut WeakDom, dom_parent: Ref) {
|
fn copy_children(
|
||||||
let children: Vec<Ref> = tree
|
tree: &librojo::RojoTree,
|
||||||
.get_instance(parent_ref)
|
parent_ref: Ref,
|
||||||
.unwrap()
|
dom: &mut WeakDom,
|
||||||
.children()
|
dom_parent: Ref,
|
||||||
.to_vec();
|
) {
|
||||||
|
let children: Vec<Ref> = tree.get_instance(parent_ref).unwrap().children().to_vec();
|
||||||
for child_ref in children {
|
for child_ref in children {
|
||||||
let child = tree.get_instance(child_ref).unwrap();
|
let child = tree.get_instance(child_ref).unwrap();
|
||||||
let builder = rbx_dom_weak::InstanceBuilder::new(child.class_name().as_str())
|
let builder = rbx_dom_weak::InstanceBuilder::new(child.class_name().as_str())
|
||||||
|
|
@ -224,7 +226,8 @@ fn syncback_matching_ufowave_textures() {
|
||||||
let effective_old_face = old_face.or(Some(5));
|
let effective_old_face = old_face.or(Some(5));
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
new_face, effective_old_face,
|
new_face,
|
||||||
|
effective_old_face,
|
||||||
"Face mismatch: input {:?} (name={}) matched to expected {:?} (name={})",
|
"Face mismatch: input {:?} (name={}) matched to expected {:?} (name={})",
|
||||||
new_face,
|
new_face,
|
||||||
input_dom.get_by_ref(*new_ref).unwrap().name,
|
input_dom.get_by_ref(*new_ref).unwrap().name,
|
||||||
|
|
@ -303,8 +306,7 @@ fn forward_matching_ufowave_textures() {
|
||||||
assert!(!snap_textures.is_empty(), "No Texture children found");
|
assert!(!snap_textures.is_empty(), "No Texture children found");
|
||||||
|
|
||||||
// Run forward sync matching
|
// Run forward sync matching
|
||||||
let result =
|
let result = librojo::snapshot::matching::match_forward(snap_textures, &tree_textures, &tree);
|
||||||
librojo::snapshot::matching::match_forward(snap_textures, &tree_textures, &tree);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.matched.len(),
|
result.matched.len(),
|
||||||
|
|
@ -344,10 +346,7 @@ fn forward_matching_ufowave_textures() {
|
||||||
// Both omitted: both at default, fine
|
// Both omitted: both at default, fine
|
||||||
}
|
}
|
||||||
(Some(sv), None) => {
|
(Some(sv), None) => {
|
||||||
panic!(
|
panic!("Snap has Face={:?} but tree has none", sv);
|
||||||
"Snap has Face={:?} but tree has none",
|
|
||||||
sv
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue