From 0877ca70eef09e5284969e6ef780a7d9bbe00fa5 Mon Sep 17 00:00:00 2001 From: kennethloeffler Date: Wed, 30 Oct 2024 12:13:41 +0000 Subject: [PATCH 1/2] Change type of InstanceBuilder.properties to Vec<(Ustr, Variant)> --- rbx_dom_weak/src/dom.rs | 6 +++++- rbx_dom_weak/src/instance.rs | 17 ++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/rbx_dom_weak/src/dom.rs b/rbx_dom_weak/src/dom.rs index 3b43ea3f0..704659498 100644 --- a/rbx_dom_weak/src/dom.rs +++ b/rbx_dom_weak/src/dom.rs @@ -123,7 +123,11 @@ impl WeakDom { parent, name: builder.name, class: builder.class, - properties: builder.properties, + properties: builder + .properties + .into_iter() + .map(|(k, v)| (k, v)) + .collect(), }, ); diff --git a/rbx_dom_weak/src/instance.rs b/rbx_dom_weak/src/instance.rs index 9118a8b7b..3b07ff3b1 100644 --- a/rbx_dom_weak/src/instance.rs +++ b/rbx_dom_weak/src/instance.rs @@ -1,8 +1,6 @@ use rbx_types::{Ref, Variant}; use ustr::{Ustr, UstrMap}; -use crate::UstrMapExt; - /** Represents an instance that can be turned into a new [`WeakDom`][crate::WeakDom], or inserted into an existing one. @@ -37,7 +35,7 @@ pub struct InstanceBuilder { pub(crate) referent: Ref, pub(crate) name: String, pub(crate) class: Ustr, - pub(crate) properties: UstrMap, + pub(crate) properties: Vec<(Ustr, Variant)>, pub(crate) children: Vec, } @@ -52,7 +50,7 @@ impl InstanceBuilder { referent: Ref::new(), name, class, - properties: UstrMap::new(), + properties: Vec::new(), children: Vec::new(), } } @@ -67,7 +65,7 @@ impl InstanceBuilder { referent: Ref::new(), name, class, - properties: UstrMap::with_capacity(capacity), + properties: Vec::with_capacity(capacity), children: Vec::new(), } } @@ -78,7 +76,7 @@ impl InstanceBuilder { referent: Ref::new(), name: String::new(), class: Ustr::default(), - properties: UstrMap::new(), + properties: Vec::new(), children: Vec::new(), } } @@ -124,18 +122,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.insert(key.into(), value.into()); + self.properties.push((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.insert(key.into(), value.into()); + self.properties.push((key.into(), value.into())); } /// Check if the `InstanceBuilder` already has a property with the given key. pub fn has_property>(&self, key: K) -> bool { - self.properties.contains_key(&key.into()) + let key = key.into(); + self.properties.iter().find(|(k, _)| *k == key).is_some() } /// Add multiple properties to the `InstanceBuilder` at once. From 555ccfc87b80ea49bdfaa0ab704f8395eac1e7f7 Mon Sep 17 00:00:00 2001 From: kennethloeffler Date: Wed, 30 Oct 2024 12:36:33 +0000 Subject: [PATCH 2/2] Fix clippy lints --- rbx_dom_weak/src/dom.rs | 6 +----- rbx_dom_weak/src/instance.rs | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/rbx_dom_weak/src/dom.rs b/rbx_dom_weak/src/dom.rs index 704659498..81c942bb3 100644 --- a/rbx_dom_weak/src/dom.rs +++ b/rbx_dom_weak/src/dom.rs @@ -123,11 +123,7 @@ impl WeakDom { parent, name: builder.name, class: builder.class, - properties: builder - .properties - .into_iter() - .map(|(k, v)| (k, v)) - .collect(), + properties: builder.properties.into_iter().collect(), }, ); diff --git a/rbx_dom_weak/src/instance.rs b/rbx_dom_weak/src/instance.rs index 3b07ff3b1..33535ab54 100644 --- a/rbx_dom_weak/src/instance.rs +++ b/rbx_dom_weak/src/instance.rs @@ -134,7 +134,7 @@ impl InstanceBuilder { /// 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().find(|(k, _)| *k == key).is_some() + self.properties.iter().any(|(k, _)| *k == key) } /// Add multiple properties to the `InstanceBuilder` at once.