Skip to content

Commit d85a799

Browse files
committed
assume migration is always to a property on the same class
1 parent 5d2d062 commit d85a799

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

rbx_binary/src/core.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,13 +402,14 @@ impl<'db> PropertyDescriptors<'db> {
402402
}
403403
}
404404

405-
/// Find both the canonical and serialized property descriptors for a given
406-
/// class and property name pair. These might be the same descriptor!
405+
/// Find the superclass which contains the specified property,
406+
/// extract the canonical and serialized property descriptors,
407+
/// and return both.
407408
pub fn find_property_descriptors<'db>(
408409
database: &'db ReflectionDatabase<'db>,
409410
class_descriptor: Option<&'db ClassDescriptor<'db>>,
410411
property_name: &str,
411-
) -> Option<PropertyDescriptors<'db>> {
412+
) -> Option<(&'db ClassDescriptor<'db>, PropertyDescriptors<'db>)> {
412413
// Checking the class descriptor is ugly without an optional
413414
// return value, and all the call sites need this precise logic.
414415
let class_descriptor = class_descriptor?;
@@ -425,7 +426,8 @@ pub fn find_property_descriptors<'db>(
425426

426427
// Extract the canonical and serialized property descriptors
427428
// from the class and property descriptors
428-
PropertyDescriptors::new(class, prop)
429+
let descriptors = PropertyDescriptors::new(class, prop)?;
430+
Some((class, descriptors))
429431
}
430432

431433
/// Given the canonical property descriptor for a logical property along with

rbx_binary/src/deserializer/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn find_canonical_property<'de>(
104104
// find_property_descriptors accepts Option<ClassDescriptor>
105105
let class_descriptor = database.classes.get(class_name);
106106
match find_property_descriptors(database, class_descriptor, prop_name) {
107-
Some(descriptors) => {
107+
Some((_, descriptors)) => {
108108
// If this descriptor is known but wasn't supposed to be
109109
// serialized, we should skip it.
110110
//

rbx_binary/src/serializer/state.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ use rbx_reflection::{
2525
use crate::{
2626
chunk::ChunkBuilder,
2727
core::{
28-
find_property_descriptors, RbxWriteExt, FILE_MAGIC_HEADER, FILE_SIGNATURE, FILE_VERSION,
28+
find_property_descriptors, PropertyDescriptors, RbxWriteExt, FILE_MAGIC_HEADER,
29+
FILE_SIGNATURE, FILE_VERSION,
2930
},
3031
types::Type,
3132
Serializer,
@@ -346,7 +347,7 @@ impl<'dom, 'db, W: Write> SerializerState<'dom, 'db, W> {
346347

347348
let database = self.serializer.database;
348349
match find_property_descriptors(database, type_info.class_descriptor, prop_name) {
349-
Some(descriptors) => {
350+
Some((superclass_descriptor, descriptors)) => {
350351
// For any properties that do not serialize, we can skip
351352
// adding them to the set of type_infos.
352353
let serialized = match descriptors.serialized {
@@ -360,11 +361,16 @@ impl<'dom, 'db, W: Write> SerializerState<'dom, 'db, W> {
360361
// information of the new property instead of the old
361362
// property, because migrated properties should not
362363
// serialize
363-
let new_descriptors = find_property_descriptors(
364-
database,
365-
type_info.class_descriptor,
366-
&prop_migration.new_property_name,
367-
);
364+
//
365+
// Assume that the migration will always be
366+
// directed to a property on the same class.
367+
// This avoids re-walking the superclasses.
368+
let new_descriptors = superclass_descriptor
369+
.properties
370+
.get(prop_migration.new_property_name.as_str())
371+
.and_then(|prop| {
372+
PropertyDescriptors::new(superclass_descriptor, prop)
373+
});
368374

369375
migration = Some(prop_migration);
370376

0 commit comments

Comments
 (0)