Remove stable_hash feature and use environment variable.

This commit is contained in:
Stephen Chung
2022-09-27 13:23:47 +08:00
parent a518ab62bb
commit 2ecf44a48e
6 changed files with 41 additions and 7 deletions

4
src/config.rs Normal file
View File

@@ -0,0 +1,4 @@
//! Configuration settings for this Rhai build
#![allow(dead_code)]
pub const AHASH_SEED: Option<[u64; 4]> = None;

View File

@@ -1,5 +1,6 @@
//! Module containing utilities to hash functions and function calls.
use crate::config;
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use std::{
@@ -74,8 +75,8 @@ impl BuildHasher for StraightHasherBuilder {
#[inline(always)]
#[must_use]
pub fn get_hasher() -> ahash::AHasher {
if cfg!(feature = "stable_hash") {
ahash::RandomState::with_seeds(42, 999, 123, 0).build_hasher()
if let Some([seed1, seed2, seed3, seed4]) = config::AHASH_SEED {
ahash::RandomState::with_seeds(seed1, seed2, seed3, seed4).build_hasher()
} else {
ahash::AHasher::default()
}

View File

@@ -83,6 +83,7 @@ use std::prelude::v1::*;
// Internal modules
mod api;
mod ast;
mod config;
mod engine;
mod eval;
mod func;
@@ -224,7 +225,7 @@ pub mod debugger {
/// An identifier in Rhai. [`SmartString`](https://crates.io/crates/smartstring) is used because most
/// identifiers are ASCII and short, fewer than 23 characters, so they can be stored inline.
#[cfg(not(feature = "internals"))]
pub(crate) type Identifier = SmartString;
type Identifier = SmartString;
/// An identifier in Rhai. [`SmartString`](https://crates.io/crates/smartstring) is used because most
/// identifiers are ASCII and short, fewer than 23 characters, so they can be stored inline.
@@ -237,7 +238,7 @@ pub use func::Shared;
/// Alias to [`RefCell`][std::cell::RefCell] or [`RwLock`][std::sync::RwLock] depending on the `sync` feature flag.
pub use func::Locked;
pub(crate) use func::{calc_fn_hash, calc_fn_params_hash, calc_var_hash, combine_hashes};
use func::{calc_fn_hash, calc_fn_params_hash, calc_var_hash, combine_hashes};
pub use rhai_codegen::*;
@@ -429,7 +430,7 @@ type FnArgsVec<T> = smallvec::SmallVec<[T; 5]>;
#[cfg(feature = "no_closure")]
type FnArgsVec<T> = crate::StaticVec<T>;
pub(crate) type SmartString = smartstring::SmartString<smartstring::LazyCompact>;
type SmartString = smartstring::SmartString<smartstring::LazyCompact>;
// Compiler guards against mutually-exclusive feature flags