diff --git a/crates/iddqd/src/id_hash_map/imp.rs b/crates/iddqd/src/id_hash_map/imp.rs index ba27140..5955a0f 100644 --- a/crates/iddqd/src/id_hash_map/imp.rs +++ b/crates/iddqd/src/id_hash_map/imp.rs @@ -15,7 +15,6 @@ use crate::{ map_hash::MapHash, }, }; -use alloc::collections::BTreeSet; use core::{ fmt, hash::{BuildHasher, Hash}, @@ -1508,8 +1507,6 @@ impl IdHashMap { &mut self, value: T, ) -> Result> { - let mut duplicates = BTreeSet::new(); - // Check for duplicates *before* inserting the new item, because we // don't want to partially insert the new item and then have to roll // back. @@ -1522,21 +1519,17 @@ impl IdHashMap { .entry(state, key, |index| self.items[index].key()) { hash_table::Entry::Occupied(slot) => { - duplicates.insert(slot.get()); - None + let index = slot.get(); + return Err(DuplicateItem::__internal_new( + value, + vec![&self.items[index]], + )); } - hash_table::Entry::Vacant(slot) => Some(slot), + hash_table::Entry::Vacant(slot) => slot, }; - if !duplicates.is_empty() { - return Err(DuplicateItem::__internal_new( - value, - duplicates.iter().map(|ix| &self.items[*ix]).collect(), - )); - } - let next_index = self.items.assert_can_grow().insert(value); - entry.unwrap().insert(next_index); + entry.insert(next_index); Ok(next_index) } diff --git a/crates/iddqd/src/id_ord_map/imp.rs b/crates/iddqd/src/id_ord_map/imp.rs index 6fd02cb..b533261 100644 --- a/crates/iddqd/src/id_ord_map/imp.rs +++ b/crates/iddqd/src/id_ord_map/imp.rs @@ -13,7 +13,6 @@ use crate::{ map_hash::MapHash, }, }; -use alloc::collections::BTreeSet; use core::{ fmt, hash::{BuildHasher, Hash}, @@ -1468,8 +1467,6 @@ impl IdOrdMap { &mut self, value: T, ) -> Result> { - let mut duplicates = BTreeSet::new(); - // Check for duplicates *before* inserting the new item, because we // don't want to partially insert the new item and then have to roll // back. @@ -1482,14 +1479,10 @@ impl IdOrdMap { .key_to_item .find_index(&key, |index| self.items[index].key()) { - duplicates.insert(index); - } - - if !duplicates.is_empty() { drop(key); return Err(DuplicateItem::__internal_new( value, - duplicates.iter().map(|ix| &self.items[*ix]).collect(), + vec![&self.items[index]], )); } }