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

View File

@@ -308,9 +308,10 @@ impl Engine {
engine
}
/// Get an interned string.
#[must_use]
/// Get an interned [string][ImmutableString].
#[cfg(not(feature = "internals"))]
#[inline(always)]
#[must_use]
pub(crate) fn get_interned_string(
&self,
string: impl AsRef<str> + Into<ImmutableString>,
@@ -318,6 +319,28 @@ impl Engine {
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.
#[inline]
pub(crate) fn check_return_value(&self, result: RhaiResult, _pos: Position) -> RhaiResult {