diff --git a/Cargo.toml b/Cargo.toml index ae6183288..2ecd58a94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -139,7 +139,7 @@ glam = "0.25.0" heck = "0.5.0-rc.1" hmac = "0.12.1" image = "0.24.6" -indexmap = "2.0.0" +indexmap = "2.2.1" itertools = "0.12.0" java_string = { path = "crates/java_string", version = "0.1.2" } lru = "0.12.0" diff --git a/crates/valence_entity/src/active_status_effects.rs b/crates/valence_entity/src/active_status_effects.rs index 5ab1492ae..427ca01ee 100644 --- a/crates/valence_entity/src/active_status_effects.rs +++ b/crates/valence_entity/src/active_status_effects.rs @@ -212,7 +212,7 @@ impl ActiveStatusEffects { /// Removes an effect. fn remove_effect(&mut self, effect: StatusEffect) { - self.current_effects.remove(&effect); + self.current_effects.swap_remove(&effect); } /// Removes all effects. diff --git a/crates/valence_entity/src/attributes.rs b/crates/valence_entity/src/attributes.rs index d6a3399ef..b23cd73e4 100644 --- a/crates/valence_entity/src/attributes.rs +++ b/crates/valence_entity/src/attributes.rs @@ -133,9 +133,9 @@ impl EntityAttributeInstance { /// Removes a modifier. pub fn remove_modifier(&mut self, uuid: Uuid) { - self.add_modifiers.remove(&uuid); - self.multiply_base_modifiers.remove(&uuid); - self.multiply_total_modifiers.remove(&uuid); + self.add_modifiers.swap_remove(&uuid); + self.multiply_base_modifiers.swap_remove(&uuid); + self.multiply_total_modifiers.swap_remove(&uuid); } /// Clears all modifiers. diff --git a/crates/valence_nbt/src/compound.rs b/crates/valence_nbt/src/compound.rs index c77c78bad..636bb2194 100644 --- a/crates/valence_nbt/src/compound.rs +++ b/crates/valence_nbt/src/compound.rs @@ -143,7 +143,30 @@ where >::Borrowed: Hash + Ord, S: Borrow<>::Borrowed>, { - self.map.remove(k.as_borrowed()) + #[cfg(feature = "preserve_order")] + return self.swap_remove(k); + #[cfg(not(feature = "preserve_order"))] + return self.map.remove(k.as_borrowed()); + } + + #[cfg(feature = "preserve_order")] + pub fn swap_remove(&mut self, k: &Q) -> Option> + where + Q: ?Sized + AsBorrowed, + >::Borrowed: Hash + Ord, + S: Borrow<>::Borrowed>, + { + self.map.swap_remove(k.as_borrowed()) + } + + #[cfg(feature = "preserve_order")] + pub fn shift_remove(&mut self, k: &Q) -> Option> + where + Q: ?Sized + AsBorrowed, + >::Borrowed: Hash + Ord, + S: Borrow<>::Borrowed>, + { + self.map.shift_remove(k.as_borrowed()) } pub fn remove_entry(&mut self, k: &Q) -> Option<(S, Value)> @@ -151,7 +174,28 @@ where S: Borrow, Q: ?Sized + Ord + Hash, { - self.map.remove_entry(k) + #[cfg(feature = "preserve_order")] + return self.swap_remove_entry(k); + #[cfg(not(feature = "preserve_order"))] + return self.map.remove_entry(k); + } + + #[cfg(feature = "preserve_order")] + pub fn swap_remove_entry(&mut self, k: &Q) -> Option<(S, Value)> + where + S: Borrow, + Q: ?Sized + Ord + Hash, + { + self.map.swap_remove_entry(k) + } + + #[cfg(feature = "preserve_order")] + pub fn shift_remove_entry(&mut self, k: &Q) -> Option<(S, Value)> + where + S: Borrow, + Q: ?Sized + Ord + Hash, + { + self.map.shift_remove_entry(k) } pub fn append(&mut self, other: &mut Self) { @@ -461,7 +505,20 @@ where } pub fn remove(self) -> Value { - self.oe.remove() + #[cfg(feature = "preserve_order")] + return self.swap_remove(); + #[cfg(not(feature = "preserve_order"))] + return self.oe.remove(); + } + + #[cfg(feature = "preserve_order")] + pub fn swap_remove(self) -> Value { + self.oe.swap_remove() + } + + #[cfg(feature = "preserve_order")] + pub fn shift_remove(self) -> Value { + self.oe.shift_remove() } }