diff --git a/rbx_dom_weak/src/dom.rs b/rbx_dom_weak/src/dom.rs index eddae288e..a6ee70e31 100644 --- a/rbx_dom_weak/src/dom.rs +++ b/rbx_dom_weak/src/dom.rs @@ -192,7 +192,7 @@ impl WeakDom { parent, name: builder.name, class: builder.class, - properties: builder.properties.into_iter().collect(), + properties: builder.properties, }, ); diff --git a/rbx_dom_weak/src/instance.rs b/rbx_dom_weak/src/instance.rs index 33535ab54..354ee15a5 100644 --- a/rbx_dom_weak/src/instance.rs +++ b/rbx_dom_weak/src/instance.rs @@ -1,3 +1,4 @@ +use ahash::HashMapExt; use rbx_types::{Ref, Variant}; use ustr::{Ustr, UstrMap}; @@ -35,7 +36,7 @@ pub struct InstanceBuilder { pub(crate) referent: Ref, pub(crate) name: String, pub(crate) class: Ustr, - pub(crate) properties: Vec<(Ustr, Variant)>, + pub(crate) properties: UstrMap, pub(crate) children: Vec, } @@ -50,7 +51,7 @@ impl InstanceBuilder { referent: Ref::new(), name, class, - properties: Vec::new(), + properties: UstrMap::new(), children: Vec::new(), } } @@ -65,7 +66,7 @@ impl InstanceBuilder { referent: Ref::new(), name, class, - properties: Vec::with_capacity(capacity), + properties: UstrMap::with_capacity(capacity), children: Vec::new(), } } @@ -76,7 +77,7 @@ impl InstanceBuilder { referent: Ref::new(), name: String::new(), class: Ustr::default(), - properties: Vec::new(), + properties: UstrMap::new(), children: Vec::new(), } } @@ -122,19 +123,19 @@ impl InstanceBuilder { /// Add a new property to the `InstanceBuilder`. pub fn with_property, V: Into>(mut self, key: K, value: V) -> Self { - self.properties.push((key.into(), value.into())); + self.properties.insert(key.into(), value.into()); self } /// Add a new property to the `InstanceBuilder`. pub fn add_property, V: Into>(&mut self, key: K, value: V) { - self.properties.push((key.into(), value.into())); + self.properties.insert(key.into(), value.into()); } /// Check if the `InstanceBuilder` already has a property with the given key. pub fn has_property>(&self, key: K) -> bool { let key = key.into(); - self.properties.iter().any(|(k, _)| *k == key) + self.properties.contains_key(&key) } /// Add multiple properties to the `InstanceBuilder` at once. diff --git a/rbx_xml/src/deserializer.rs b/rbx_xml/src/deserializer.rs index e40901184..777d030a1 100644 --- a/rbx_xml/src/deserializer.rs +++ b/rbx_xml/src/deserializer.rs @@ -4,7 +4,7 @@ use ahash::{HashMap, HashMapExt, HashSet, HashSetExt}; use log::trace; use rbx_dom_weak::{ types::{Ref, SharedString, Variant}, - InstanceBuilder, Ustr, WeakDom, + InstanceBuilder, Ustr, UstrMap, WeakDom, }; use rbx_reflection::{PropertyKind, PropertySerialization, ReflectionDatabase}; @@ -492,7 +492,7 @@ fn deserialize_instance( state.referents_to_ids.insert(referent, instance_id); } - let mut properties: HashMap = HashMap::new(); + let mut properties = UstrMap::new(); loop { match reader.expect_peek()? { @@ -539,7 +539,7 @@ fn deserialize_instance( None => instance.class.to_string(), }; - instance.properties = properties.into_iter().collect(); + instance.properties = properties; Ok(()) } @@ -548,7 +548,7 @@ fn deserialize_properties( reader: &mut XmlEventReader, state: &mut ParseState, instance_id: Ref, - props: &mut HashMap, + props: &mut UstrMap, ) -> Result<(), DecodeError> { reader.expect_start_with_name("Properties")?;