Skip to content

Commit

Permalink
Use ImmutableString for AST.
Browse files Browse the repository at this point in the history
  • Loading branch information
schungx committed Aug 13, 2022
1 parent 2874359 commit 9813f65
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Expand Up @@ -3,11 +3,8 @@ Cargo.lock
.vscode/
.cargo/
benches/results
.rhai-repl-history.txt
clippy.toml
Rhai.toml
before*
after*
**/*.bat
doc/rhai-sync.json
doc/rhai.json
4 changes: 2 additions & 2 deletions src/ast/script_fn.rs
Expand Up @@ -2,7 +2,7 @@
#![cfg(not(feature = "no_function"))]

use super::{FnAccess, StmtBlock};
use crate::{Identifier, ImmutableString, StaticVec};
use crate::{ImmutableString, StaticVec};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use std::{fmt, hash::Hash};
Expand All @@ -22,7 +22,7 @@ pub struct EncapsulatedEnviron {
/// Functions defined within the same [`AST`][crate::AST].
pub lib: crate::Shared<crate::Module>,
/// Imported [modules][crate::Module].
pub imports: Box<[(Identifier, crate::Shared<crate::Module>)]>,
pub imports: Box<[(ImmutableString, crate::Shared<crate::Module>)]>,
/// Globally-defined constants.
pub constants: Option<crate::eval::GlobalConstants>,
}
Expand Down
20 changes: 10 additions & 10 deletions src/eval/global_state.rs
Expand Up @@ -25,7 +25,7 @@ pub type GlobalConstants =
pub struct GlobalRuntimeState<'a> {
/// Stack of module names.
#[cfg(not(feature = "no_module"))]
keys: crate::StaticVec<Identifier>,
keys: crate::StaticVec<ImmutableString>,
/// Stack of imported [modules][crate::Module].
#[cfg(not(feature = "no_module"))]
modules: crate::StaticVec<crate::Shared<crate::Module>>,
Expand Down Expand Up @@ -159,7 +159,7 @@ impl GlobalRuntimeState<'_> {
self.keys
.iter()
.rev()
.position(|key| key == name)
.position(|key| key.as_str() == name)
.map(|i| len - 1 - i)
}
/// Push an imported [module][crate::Module] onto the stack.
Expand All @@ -169,7 +169,7 @@ impl GlobalRuntimeState<'_> {
#[inline(always)]
pub fn push_import(
&mut self,
name: impl Into<Identifier>,
name: impl Into<ImmutableString>,
module: impl Into<crate::Shared<crate::Module>>,
) {
self.keys.push(name.into());
Expand Down Expand Up @@ -205,7 +205,7 @@ impl GlobalRuntimeState<'_> {
#[inline]
pub(crate) fn iter_imports_raw(
&self,
) -> impl Iterator<Item = (&Identifier, &crate::Shared<crate::Module>)> {
) -> impl Iterator<Item = (&ImmutableString, &crate::Shared<crate::Module>)> {
self.keys.iter().rev().zip(self.modules.iter().rev())
}
/// Get an iterator to the stack of globally-imported [modules][crate::Module] in forward order.
Expand All @@ -216,7 +216,7 @@ impl GlobalRuntimeState<'_> {
#[inline]
pub fn scan_imports_raw(
&self,
) -> impl Iterator<Item = (&Identifier, &crate::Shared<crate::Module>)> {
) -> impl Iterator<Item = (&ImmutableString, &crate::Shared<crate::Module>)> {
self.keys.iter().zip(self.modules.iter())
}
/// Does the specified function hash key exist in the stack of globally-imported
Expand Down Expand Up @@ -310,9 +310,9 @@ impl GlobalRuntimeState<'_> {

#[cfg(not(feature = "no_module"))]
impl IntoIterator for GlobalRuntimeState<'_> {
type Item = (Identifier, crate::Shared<crate::Module>);
type Item = (ImmutableString, crate::Shared<crate::Module>);
type IntoIter = std::iter::Zip<
std::iter::Rev<smallvec::IntoIter<[Identifier; 3]>>,
std::iter::Rev<smallvec::IntoIter<[ImmutableString; 3]>>,
std::iter::Rev<smallvec::IntoIter<[crate::Shared<crate::Module>; 3]>>,
>;

Expand All @@ -327,9 +327,9 @@ impl IntoIterator for GlobalRuntimeState<'_> {

#[cfg(not(feature = "no_module"))]
impl<'a> IntoIterator for &'a GlobalRuntimeState<'_> {
type Item = (&'a Identifier, &'a crate::Shared<crate::Module>);
type Item = (&'a ImmutableString, &'a crate::Shared<crate::Module>);
type IntoIter = std::iter::Zip<
std::iter::Rev<std::slice::Iter<'a, Identifier>>,
std::iter::Rev<std::slice::Iter<'a, ImmutableString>>,
std::iter::Rev<std::slice::Iter<'a, crate::Shared<crate::Module>>>,
>;

Expand All @@ -341,7 +341,7 @@ impl<'a> IntoIterator for &'a GlobalRuntimeState<'_> {
}

#[cfg(not(feature = "no_module"))]
impl<K: Into<Identifier>, M: Into<crate::Shared<crate::Module>>> Extend<(K, M)>
impl<K: Into<ImmutableString>, M: Into<crate::Shared<crate::Module>>> Extend<(K, M)>
for GlobalRuntimeState<'_>
{
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/func/native.rs
Expand Up @@ -235,7 +235,7 @@ impl<'a> NativeCallContext<'a> {
#[inline]
pub(crate) fn iter_imports_raw(
&self,
) -> impl Iterator<Item = (&crate::Identifier, &Shared<Module>)> {
) -> impl Iterator<Item = (&crate::ImmutableString, &Shared<Module>)> {
self.global.iter().flat_map(|&m| m.iter_imports_raw())
}
/// _(internals)_ The current [`GlobalRuntimeState`], if any.
Expand Down

0 comments on commit 9813f65

Please sign in to comment.