Commit 184e197c authored by Hero Bird's avatar Hero Bird
Browse files

[pdsl_core] Use hashbrown HashMap instead of std::collections::HashMap

The problem with std::collections::HashMap is that there is no core::collections::HashMap or similar replacement for our no_std environment.
Also hashbrown seems to have superior performance.
parent bc711cb8
......@@ -22,6 +22,7 @@ parity-codec = { version = "2.0" }
parity-codec-derive = { version = "2.0" }
tiny-keccak = "1.4"
log = "0.4"
hashbrown = "0.1.7"
[dev-dependencies]
env_logger = { version = "0.6", default-features = false }
......
......@@ -18,8 +18,8 @@ use super::*;
use std::cell::Cell;
use std::collections::HashMap;
use std::collections::hash_map::Entry;
use hashbrown::HashMap;
use hashbrown::hash_map::Entry;
use std::cell::RefCell;
/// An entry in the storage of the test environment.
......
......@@ -26,10 +26,11 @@ use crate::{
};
use core::cell::RefCell;
use std::{
collections::{
HashMap,
hash_map::Entry,
use hashbrown::{
HashMap,
hash_map::{
Entry,
DefaultHashBuilder,
},
};
......@@ -54,7 +55,7 @@ pub struct SyncChunk<T> {
}
/// A single cache entry for a copy chunk cell.
type CacheEntry<'a, T> = Entry<'a, u32, Option<T>>;
type CacheEntry<'a, T> = Entry<'a, u32, Option<T>, DefaultHashBuilder>;
/// A single cell within a chunk of copy cells.
#[derive(Debug)]
......@@ -241,7 +242,7 @@ impl<T> Cache<T> {
///
/// Returns an immutable reference to the new value.
pub fn upsert(&self, n: u32, val: Option<T>) -> Option<&T> {
use std::collections::hash_map::{Entry};
use hashbrown::hash_map::{Entry};
let elems: &mut HashMap<u32, Option<T>> = unsafe {
&mut *self.elems.as_ptr()
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment