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

View File

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

View File

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

View File

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