Reduce API changes.

This commit is contained in:
Stephen Chung 2022-08-19 13:21:47 +08:00
parent f9d74fe313
commit a51f6138f6
5 changed files with 29 additions and 6 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -308,9 +308,10 @@ impl Engine {
engine engine
} }
/// Get an interned string. /// Get an interned [string][ImmutableString].
#[must_use] #[cfg(not(feature = "internals"))]
#[inline(always)] #[inline(always)]
#[must_use]
pub(crate) fn get_interned_string( pub(crate) fn get_interned_string(
&self, &self,
string: impl AsRef<str> + Into<ImmutableString>, string: impl AsRef<str> + Into<ImmutableString>,
@ -318,6 +319,28 @@ impl Engine {
locked_write(&self.interned_strings).get(string).into() locked_write(&self.interned_strings).get(string).into()
} }
/// _(internals)_ Get an interned [string][ImmutableString].
/// Exported under the `internals` feature only.
///
/// [`Engine`] keeps a cache of [`ImmutableString`] instances and tries to avoid new allocations
/// when an existing instance is found.
#[cfg(feature = "internals")]
#[inline(always)]
#[must_use]
pub fn get_interned_string(
&self,
string: impl AsRef<str> + Into<ImmutableString>,
) -> ImmutableString {
locked_write(&self.interned_strings).get(string).into()
}
/// Get an empty [`ImmutableString`] which refers to a shared instance.
#[inline(always)]
#[must_use]
pub fn const_empty_string(&self) -> ImmutableString {
self.get_interned_string("")
}
/// Check a result to ensure that it is valid. /// Check a result to ensure that it is valid.
#[inline] #[inline]
pub(crate) fn check_return_value(&self, result: RhaiResult, _pos: Position) -> RhaiResult { pub(crate) fn check_return_value(&self, result: RhaiResult, _pos: Position) -> RhaiResult {

View File

@ -6,6 +6,7 @@ use crate::{Dynamic, Engine, Module, Scope};
use std::prelude::v1::*; use std::prelude::v1::*;
/// Context of a script evaluation process. /// Context of a script evaluation process.
#[derive(Debug)]
#[allow(dead_code)] #[allow(dead_code)]
pub struct EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 'pc, 't, 'pt> { pub struct EvalContext<'a, 's, 'ps, 'g, 'pg, 'c, 'pc, 't, 'pt> {
/// The current [`Engine`]. /// The current [`Engine`].

View File

@ -20,7 +20,7 @@ use std::{
}; };
/// _(internals)_ A type containing commands to control the tokenizer. /// _(internals)_ A type containing commands to control the tokenizer.
#[derive(Debug, Clone, Eq, PartialEq, Hash)] #[derive(Debug, Clone, Eq, PartialEq, Default, Hash)]
pub struct TokenizerControlBlock { pub struct TokenizerControlBlock {
/// Is the current tokenizer position within an interpolated text string? /// Is the current tokenizer position within an interpolated text string?
/// This flag allows switching the tokenizer back to _text_ parsing after an interpolation stream. /// This flag allows switching the tokenizer back to _text_ parsing after an interpolation stream.
@ -1117,7 +1117,7 @@ impl From<Token> for String {
/// _(internals)_ State of the tokenizer. /// _(internals)_ State of the tokenizer.
/// Exported under the `internals` feature only. /// Exported under the `internals` feature only.
#[derive(Debug, Clone, Eq, PartialEq)] #[derive(Debug, Clone, Eq, PartialEq, Default)]
pub struct TokenizeState { pub struct TokenizeState {
/// Maximum length of a string. /// Maximum length of a string.
pub max_string_size: Option<NonZeroUsize>, pub max_string_size: Option<NonZeroUsize>,