Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use UstrSet for TypeInfo.properties_visited and TypeInfo.aliases #469

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions rbx_binary/src/serializer/state.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::{
borrow::{Borrow, Cow},
collections::{btree_map, BTreeMap, BTreeSet},
collections::{btree_map, BTreeMap},
convert::TryInto,
io::Write,
};

use ahash::{HashMap, HashMapExt, HashSet, HashSetExt};
use ahash::{HashMap, HashMapExt, HashSetExt};
use rbx_dom_weak::{
types::{
Attributes, Axes, BinaryString, BrickColor, CFrame, Color3, Color3uint8, ColorSequence,
Expand All @@ -14,7 +14,7 @@ use rbx_dom_weak::{
SecurityCapabilities, SharedString, Tags, UDim, UDim2, UniqueId, Variant, VariantType,
Vector2, Vector3, Vector3int16,
},
Instance, Ustr, WeakDom,
Instance, Ustr, UstrSet, WeakDom,
};

use rbx_reflection::{
Expand Down Expand Up @@ -99,7 +99,7 @@ struct TypeInfo<'dom, 'db> {
/// A set containing the properties that we have seen so far in the file and
/// processed. This helps us avoid traversing the reflection database
/// multiple times if there are many copies of the same kind of instance.
properties_visited: HashSet<(Ustr, VariantType)>,
properties_visited: UstrSet,
}

/// A property on a specific class that our serializer knows about.
Expand Down Expand Up @@ -129,7 +129,7 @@ struct PropInfo<'db> {
/// allocate) in most cases. However, if an instance is missing a property
/// from its canonical name, but does have another variant, we can use this
/// set to recover and map those values.
aliases: BTreeSet<Ustr>,
aliases: UstrSet,

/// The default value for this property that should be used if any instances
/// are missing this property.
Expand Down Expand Up @@ -206,7 +206,7 @@ impl<'dom, 'db> TypeInfos<'dom, 'db> {
PropInfo {
prop_type: Type::String,
serialized_name: "Name".into(),
aliases: BTreeSet::new(),
aliases: UstrSet::new(),
default_value: Cow::Owned(Variant::String(String::new())),
migration: None,
},
Expand All @@ -218,7 +218,7 @@ impl<'dom, 'db> TypeInfos<'dom, 'db> {
instances: Vec::new(),
properties,
class_descriptor,
properties_visited: HashSet::new(),
properties_visited: UstrSet::new(),
});
}

Expand Down Expand Up @@ -330,19 +330,14 @@ impl<'dom, 'db, W: Write> SerializerState<'dom, 'db, W> {
}
}

// Skip this property+value type pair if we've already seen it.
if type_info
.properties_visited
.contains(&(*prop_name, prop_value.ty()))
{
// Skip this property if we've already seen it.
if type_info.properties_visited.contains(prop_name) {
continue;
}

// ...but add it to the set of visited properties if we haven't seen
// it.
type_info
.properties_visited
.insert((*prop_name, prop_value.ty()));
type_info.properties_visited.insert(*prop_name);

let canonical_name;
let serialized_name;
Expand Down Expand Up @@ -462,7 +457,7 @@ impl<'dom, 'db, W: Write> SerializerState<'dom, 'db, W> {
PropInfo {
prop_type: ser_type,
serialized_name,
aliases: BTreeSet::new(),
aliases: UstrSet::new(),
default_value,
migration,
},
Expand Down