mirror of
https://gitee.com/openharmony/third_party_rust_hashbrown
synced 2024-11-23 12:59:40 +00:00
8d6c278366
Sometimes a map is constructed when it is known that all keys are unique (e. e. if keys are coming from another map or from a sorted/deduplicated iterator). In this case we can make insertion faster by skipping a check that a key already exists in the map. `insert_unique_unchecked` is guaranteed to be memory-safe, but does not guarantee anything beyond that: if inserted key is not unique, `HashMap` can panic, loop forever, return incorrect entry etc. Added simple benchmark. `insert_unique_unchecked` is about 30% faster than `insert`. Your mileage may vary of course. Similar PR was [added to `indexmap` crate](https://github.com/bluss/indexmap/pull/200) and they asked to discuss the name of the operation with `hashbrown` crate owners to come to the same naming convention (if `hashbrown` is willing to have the same operation). |
||
---|---|---|
.. | ||
bench.rs | ||
insert_unique_unchecked.rs |