Optimization: less HashMap, more AHashMap

This commit is contained in:
Emil Ernerfeldt 2021-10-09 15:22:36 +02:00
parent 22a3a75eb5
commit cca11ea9cc
4 changed files with 10 additions and 10 deletions

View file

@ -1,15 +1,15 @@
use crate::any::element::{AnyMapElement, AnyMapTrait}; use crate::any::element::{AnyMapElement, AnyMapTrait};
use crate::epaint::ahash::AHashMap;
use std::any::TypeId; use std::any::TypeId;
use std::collections::HashMap;
use std::hash::Hash; use std::hash::Hash;
/// Stores any object by `Key`. /// Stores any object by `Key`.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct AnyMap<Key: Hash + Eq>(HashMap<Key, AnyMapElement>); pub struct AnyMap<Key: Hash + Eq>(AHashMap<Key, AnyMapElement>);
impl<Key: Hash + Eq> Default for AnyMap<Key> { impl<Key: Hash + Eq> Default for AnyMap<Key> {
fn default() -> Self { fn default() -> Self {
AnyMap(HashMap::new()) AnyMap(AHashMap::new())
} }
} }

View file

@ -1,16 +1,16 @@
use crate::any::serializable::element::{AnyMapElement, AnyMapTrait}; use crate::any::serializable::element::{AnyMapElement, AnyMapTrait};
use crate::any::serializable::type_id::TypeId; use crate::any::serializable::type_id::TypeId;
use crate::epaint::ahash::AHashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::hash::Hash; use std::hash::Hash;
/// Stores any object by `Key`, and can be de/serialized. /// Stores any object by `Key`, and can be de/serialized.
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct AnyMap<Key: Hash + Eq>(HashMap<Key, AnyMapElement>); pub struct AnyMap<Key: Hash + Eq>(AHashMap<Key, AnyMapElement>);
impl<Key: Hash + Eq> Default for AnyMap<Key> { impl<Key: Hash + Eq> Default for AnyMap<Key> {
fn default() -> Self { fn default() -> Self {
AnyMap(HashMap::new()) AnyMap(AHashMap::new())
} }
} }

View file

@ -1,14 +1,14 @@
use crate::any::serializable::element::{AnyMapElement, AnyMapTrait}; use crate::any::serializable::element::{AnyMapElement, AnyMapTrait};
use crate::any::serializable::type_id::TypeId; use crate::any::serializable::type_id::TypeId;
use crate::epaint::ahash::AHashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// Maps types to a single instance of that type. /// Maps types to a single instance of that type.
/// ///
/// Used to store state per widget type. In effect a sort of singleton storage. /// Used to store state per widget type. In effect a sort of singleton storage.
/// Similar to [the `typemap` crate](https://docs.rs/typemap/0.3.3/typemap/) but allows serialization. /// Similar to [the `typemap` crate](https://docs.rs/typemap/0.3.3/typemap/) but allows serialization.
#[derive(Clone, Debug, Default, Deserialize, Serialize)] #[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct TypeMap(HashMap<TypeId, AnyMapElement>); pub struct TypeMap(AHashMap<TypeId, AnyMapElement>);
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View file

@ -1,13 +1,13 @@
use crate::any::element::{AnyMapElement, AnyMapTrait}; use crate::any::element::{AnyMapElement, AnyMapTrait};
use crate::epaint::ahash::AHashMap;
use std::any::TypeId; use std::any::TypeId;
use std::collections::HashMap;
/// Maps types to a single instance of that type. /// Maps types to a single instance of that type.
/// ///
/// Used to store state per widget type. In effect a sort of singleton storage. /// Used to store state per widget type. In effect a sort of singleton storage.
/// Similar to [the `typemap` crate](https://docs.rs/typemap/0.3.3/typemap/). /// Similar to [the `typemap` crate](https://docs.rs/typemap/0.3.3/typemap/).
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
pub struct TypeMap(HashMap<TypeId, AnyMapElement>); pub struct TypeMap(AHashMap<TypeId, AnyMapElement>);
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------