Use StraightHashMap.
This commit is contained in:
parent
557b368fdb
commit
dbac4d5689
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use super::{ASTFlags, ASTNode, BinaryExpr, Expr, FnCallExpr, Ident};
|
use super::{ASTFlags, ASTNode, BinaryExpr, Expr, FnCallExpr, Ident};
|
||||||
use crate::engine::KEYWORD_EVAL;
|
use crate::engine::KEYWORD_EVAL;
|
||||||
|
use crate::func::StraightHashMap;
|
||||||
use crate::tokenizer::Token;
|
use crate::tokenizer::Token;
|
||||||
use crate::types::Span;
|
use crate::types::Span;
|
||||||
use crate::{calc_fn_hash, Position, StaticVec, INT};
|
use crate::{calc_fn_hash, Position, StaticVec, INT};
|
||||||
@ -9,9 +10,8 @@ use crate::{calc_fn_hash, Position, StaticVec, INT};
|
|||||||
use std::prelude::v1::*;
|
use std::prelude::v1::*;
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Borrow,
|
borrow::Borrow,
|
||||||
collections::BTreeMap,
|
|
||||||
fmt,
|
fmt,
|
||||||
hash::Hash,
|
hash::{Hash, Hasher},
|
||||||
mem,
|
mem,
|
||||||
num::NonZeroUsize,
|
num::NonZeroUsize,
|
||||||
ops::{Deref, DerefMut, Range, RangeInclusive},
|
ops::{Deref, DerefMut, Range, RangeInclusive},
|
||||||
@ -303,18 +303,31 @@ pub type CaseBlocksList = smallvec::SmallVec<[usize; 1]>;
|
|||||||
|
|
||||||
/// _(internals)_ A type containing all cases for a `switch` statement.
|
/// _(internals)_ A type containing all cases for a `switch` statement.
|
||||||
/// Exported under the `internals` feature only.
|
/// Exported under the `internals` feature only.
|
||||||
#[derive(Debug, Clone, Hash)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct SwitchCasesCollection {
|
pub struct SwitchCasesCollection {
|
||||||
/// List of [`ConditionalExpr`]'s.
|
/// List of [`ConditionalExpr`]'s.
|
||||||
pub expressions: StaticVec<ConditionalExpr>,
|
pub expressions: StaticVec<ConditionalExpr>,
|
||||||
/// Dictionary mapping value hashes to [`ConditionalExpr`]'s.
|
/// Dictionary mapping value hashes to [`ConditionalExpr`]'s.
|
||||||
pub cases: BTreeMap<u64, CaseBlocksList>,
|
pub cases: StraightHashMap<CaseBlocksList>,
|
||||||
/// List of range cases.
|
/// List of range cases.
|
||||||
pub ranges: StaticVec<RangeCase>,
|
pub ranges: StaticVec<RangeCase>,
|
||||||
/// Statements block for the default case (there can be no condition for the default case).
|
/// Statements block for the default case (there can be no condition for the default case).
|
||||||
pub def_case: Option<usize>,
|
pub def_case: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Hash for SwitchCasesCollection {
|
||||||
|
#[inline(always)]
|
||||||
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
|
self.expressions.hash(state);
|
||||||
|
|
||||||
|
self.cases.len().hash(state);
|
||||||
|
self.cases.iter().for_each(|kv| kv.hash(state));
|
||||||
|
|
||||||
|
self.ranges.hash(state);
|
||||||
|
self.def_case.hash(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Number of items to keep inline for [`StmtBlockContainer`].
|
/// Number of items to keep inline for [`StmtBlockContainer`].
|
||||||
#[cfg(not(feature = "no_std"))]
|
#[cfg(not(feature = "no_std"))]
|
||||||
const STMT_BLOCK_INLINE_SIZE: usize = 8;
|
const STMT_BLOCK_INLINE_SIZE: usize = 8;
|
||||||
|
@ -1121,7 +1121,7 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut expressions = StaticVec::<ConditionalExpr>::new();
|
let mut expressions = StaticVec::<ConditionalExpr>::new();
|
||||||
let mut cases = BTreeMap::<u64, CaseBlocksList>::new();
|
let mut cases = StraightHashMap::<CaseBlocksList>::default();
|
||||||
let mut ranges = StaticVec::<RangeCase>::new();
|
let mut ranges = StaticVec::<RangeCase>::new();
|
||||||
let mut def_case = None;
|
let mut def_case = None;
|
||||||
let mut def_case_pos = Position::NONE;
|
let mut def_case_pos = Position::NONE;
|
||||||
|
Loading…
Reference in New Issue
Block a user