Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion rbx_dom_weak/src/dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl WeakDom {
parent,
name: builder.name,
class: builder.class,
properties: builder.properties.into_iter().collect(),
properties: builder.properties,
},
);

Expand Down
15 changes: 8 additions & 7 deletions rbx_dom_weak/src/instance.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use ahash::HashMapExt;
use rbx_types::{Ref, Variant};
use ustr::{Ustr, UstrMap};

Expand Down Expand Up @@ -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<Variant>,
pub(crate) children: Vec<InstanceBuilder>,
}

Expand All @@ -50,7 +51,7 @@ impl InstanceBuilder {
referent: Ref::new(),
name,
class,
properties: Vec::new(),
properties: UstrMap::new(),
children: Vec::new(),
}
}
Expand All @@ -65,7 +66,7 @@ impl InstanceBuilder {
referent: Ref::new(),
name,
class,
properties: Vec::with_capacity(capacity),
properties: UstrMap::with_capacity(capacity),
children: Vec::new(),
}
}
Expand All @@ -76,7 +77,7 @@ impl InstanceBuilder {
referent: Ref::new(),
name: String::new(),
class: Ustr::default(),
properties: Vec::new(),
properties: UstrMap::new(),
children: Vec::new(),
}
}
Expand Down Expand Up @@ -122,19 +123,19 @@ impl InstanceBuilder {

/// Add a new property to the `InstanceBuilder`.
pub fn with_property<K: Into<Ustr>, V: Into<Variant>>(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<K: Into<Ustr>, V: Into<Variant>>(&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<K: Into<Ustr>>(&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.
Expand Down
8 changes: 4 additions & 4 deletions rbx_xml/src/deserializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -492,7 +492,7 @@ fn deserialize_instance<R: Read>(
state.referents_to_ids.insert(referent, instance_id);
}

let mut properties: HashMap<Ustr, Variant> = HashMap::new();
let mut properties = UstrMap::new();

loop {
match reader.expect_peek()? {
Expand Down Expand Up @@ -539,7 +539,7 @@ fn deserialize_instance<R: Read>(
None => instance.class.to_string(),
};

instance.properties = properties.into_iter().collect();
instance.properties = properties;

Ok(())
}
Expand All @@ -548,7 +548,7 @@ fn deserialize_properties<R: Read>(
reader: &mut XmlEventReader<R>,
state: &mut ParseState,
instance_id: Ref,
props: &mut HashMap<Ustr, Variant>,
props: &mut UstrMap<Variant>,
) -> Result<(), DecodeError> {
reader.expect_start_with_name("Properties")?;

Expand Down