Use more const functions.

This commit is contained in:
Stephen Chung 2021-11-27 14:24:06 +08:00
parent 280b5b405e
commit abe6b4a29b
7 changed files with 19 additions and 14 deletions

View File

@ -19,7 +19,7 @@ categories = ["no-std", "embedded", "wasm", "parser-implementations"]
smallvec = { version = "1.7", default-features = false, features = ["union", "const_new" ] }
ahash = { version = "0.7", default-features = false }
num-traits = { version = "0.2", default-features = false }
smartstring = { version = "0.2.7", default-features = false }
smartstring = { version = "0.2.8", default-features = false }
rhai_codegen = { version = "1.2", path = "codegen", default-features = false }
[features]

View File

@ -1159,7 +1159,7 @@ impl Engine {
progress: None,
#[cfg(not(feature = "no_optimize"))]
optimization_level: Default::default(),
optimization_level: crate::OptimizationLevel::default(),
#[cfg(not(feature = "unchecked"))]
limits: Limits::new(),

View File

@ -49,7 +49,7 @@ impl BuildHasher for StraightHasherBuilder {
#[inline(always)]
#[must_use]
pub fn get_hasher() -> ahash::AHasher {
Default::default()
ahash::AHasher::default()
}
/// Calculate a [`u64`] hash key from a namespace-qualified variable name.

View File

@ -121,7 +121,7 @@ impl FileModuleResolver {
base_path: None,
extension: extension.into(),
cache_enabled: true,
cache: Default::default(),
cache: BTreeMap::new().into(),
}
}
@ -150,7 +150,7 @@ impl FileModuleResolver {
base_path: Some(path.into()),
extension: extension.into(),
cache_enabled: true,
cache: Default::default(),
cache: BTreeMap::new().into(),
}
}

View File

@ -1119,7 +1119,7 @@ pub fn optimize_into_ast(
optimization_level: OptimizationLevel,
) -> AST {
let level = if cfg!(feature = "no_optimize") {
Default::default()
OptimizationLevel::default()
} else {
optimization_level
};
@ -1140,7 +1140,7 @@ pub fn optimize_into_ast(
.map(|fn_def| crate::ast::ScriptFnDef {
name: fn_def.name.clone(),
access: fn_def.access,
body: crate::ast::StmtBlock::empty(Position::NONE),
body: crate::ast::StmtBlock::NONE,
params: fn_def.params.clone(),
lib: None,
#[cfg(not(feature = "no_module"))]

View File

@ -57,13 +57,18 @@ pub struct IdentifierBuilder(
impl IdentifierBuilder {
/// Create a new IdentifierBuilder.
#[cfg(not(feature = "no_smartstring"))]
#[inline]
#[must_use]
pub const fn new() -> Self {
Self()
}
/// Create a new IdentifierBuilder.
#[cfg(feature = "no_smartstring")]
#[inline]
#[must_use]
pub fn new() -> Self {
Self(
#[cfg(feature = "no_smartstring")]
std::collections::BTreeSet::new(),
)
Self(std::collections::BTreeSet::new())
}
/// Get an identifier from a text string.
#[inline]
@ -2013,8 +2018,8 @@ fn parse_custom_syntax(
if syntax.scope_may_be_changed {
// Add a barrier variable to the stack so earlier variables will not be matched.
// Variable searches stop at the first barrier.
let empty = state.get_identifier(SCOPE_SEARCH_BARRIER_MARKER);
state.stack.push((empty, AccessMode::ReadWrite));
let marker = state.get_identifier(SCOPE_SEARCH_BARRIER_MARKER);
state.stack.push((marker, AccessMode::ReadWrite));
}
let parse_func = syntax.parse.as_ref();

View File

@ -539,7 +539,7 @@ impl ImmutableString {
/// Create a new [`ImmutableString`].
#[inline(always)]
pub fn new() -> Self {
Self(SmartString::new().into())
Self(SmartString::new_const().into())
}
/// Consume the [`ImmutableString`] and convert it into a [`String`].
/// If there are other references to the same string, a cloned copy is returned.