Make FnPtr::fn_name_raw const.

This commit is contained in:
Stephen Chung 2021-06-29 21:47:27 +08:00
parent 0346bb874b
commit d146de4ff9
4 changed files with 18 additions and 5 deletions

View File

@ -951,7 +951,7 @@ impl Engine {
fn_ptr.clone()
} else {
FnPtr::new_unchecked(
fn_ptr.get_fn_name().clone(),
fn_ptr.fn_name_raw().clone(),
fn_ptr
.curry()
.iter()
@ -981,7 +981,7 @@ impl Engine {
if let Some(val) = map.get(fn_name) {
if let Some(fn_ptr) = val.read_lock::<FnPtr>() {
// Remap the function name
_redirected = fn_ptr.get_fn_name().clone();
_redirected = fn_ptr.fn_name_raw().clone();
fn_name = &_redirected;
// Add curried arguments
if fn_ptr.is_curried() {

View File

@ -33,12 +33,12 @@ impl FnPtr {
#[inline(always)]
#[must_use]
pub fn fn_name(&self) -> &str {
self.get_fn_name().as_ref()
self.fn_name_raw().as_ref()
}
/// Get the name of the function.
#[inline(always)]
#[must_use]
pub(crate) const fn get_fn_name(&self) -> &Identifier {
pub(crate) const fn fn_name_raw(&self) -> &Identifier {
&self.0
}
/// Get the underlying data of the function pointer.

View File

@ -106,12 +106,25 @@ impl From<String> for ImmutableString {
}
}
#[cfg(not(feature = "no_smartstring"))]
impl From<&SmartString> for ImmutableString {
#[inline(always)]
fn from(value: &SmartString) -> Self {
Self(Into::<SmartString>::into(value.as_str()).into())
}
}
#[cfg(not(feature = "no_smartstring"))]
impl From<SmartString> for ImmutableString {
#[inline(always)]
fn from(value: SmartString) -> Self {
Self(value.into())
}
}
impl From<&ImmutableString> for SmartString {
#[inline(always)]
fn from(value: &ImmutableString) -> Self {
value.as_str().into()
}
}
impl From<ImmutableString> for SmartString {
#[inline(always)]
fn from(mut value: ImmutableString) -> Self {

View File

@ -11,7 +11,7 @@ def_package!(crate:BasicFnPackage:"Basic Fn functions.", lib, {
mod fn_ptr_functions {
#[rhai_fn(name = "name", get = "name", pure)]
pub fn name(f: &mut FnPtr) -> ImmutableString {
f.get_fn_name().as_str().into()
f.fn_name_raw().into()
}
#[cfg(not(feature = "no_function"))]