Add #[cold] tags.
This commit is contained in:
parent
2458e05dcb
commit
396ec7df8a
@ -170,11 +170,8 @@ impl Engine {
|
|||||||
keyword: impl AsRef<str>,
|
keyword: impl AsRef<str>,
|
||||||
precedence: u8,
|
precedence: u8,
|
||||||
) -> Result<&mut Self, String> {
|
) -> Result<&mut Self, String> {
|
||||||
let precedence = Precedence::new(precedence);
|
let precedence =
|
||||||
|
Precedence::new(precedence).ok_or_else(|| "precedence cannot be zero".to_string())?;
|
||||||
if precedence.is_none() {
|
|
||||||
return Err("precedence cannot be zero".into());
|
|
||||||
}
|
|
||||||
|
|
||||||
let keyword = keyword.as_ref();
|
let keyword = keyword.as_ref();
|
||||||
|
|
||||||
@ -213,7 +210,8 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add to custom keywords
|
// Add to custom keywords
|
||||||
self.custom_keywords.insert(keyword.into(), precedence);
|
self.custom_keywords
|
||||||
|
.insert(keyword.into(), Some(precedence));
|
||||||
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
@ -238,6 +238,7 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Make a `Box<`[`EvalAltResult<ErrorMismatchDataType>`][ERR::ErrorMismatchDataType]`>`.
|
/// Make a `Box<`[`EvalAltResult<ErrorMismatchDataType>`][ERR::ErrorMismatchDataType]`>`.
|
||||||
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn make_type_mismatch_err<T>(&self, typ: &str, pos: Position) -> RhaiError {
|
pub(crate) fn make_type_mismatch_err<T>(&self, typ: &str, pos: Position) -> RhaiError {
|
||||||
|
@ -79,7 +79,6 @@ impl Caches<'_> {
|
|||||||
self.stack.last_mut().unwrap()
|
self.stack.last_mut().unwrap()
|
||||||
}
|
}
|
||||||
/// Push an empty function resolution cache onto the stack and make it current.
|
/// Push an empty function resolution cache onto the stack and make it current.
|
||||||
#[allow(dead_code)]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn push_fn_resolution_cache(&mut self) {
|
pub fn push_fn_resolution_cache(&mut self) {
|
||||||
self.stack.push(Default::default());
|
self.stack.push(Default::default());
|
||||||
|
@ -35,6 +35,7 @@ impl Engine {
|
|||||||
pos: Position,
|
pos: Position,
|
||||||
level: usize,
|
level: usize,
|
||||||
) -> RhaiResult {
|
) -> RhaiResult {
|
||||||
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn make_error(
|
fn make_error(
|
||||||
name: String,
|
name: String,
|
||||||
|
@ -9,7 +9,8 @@ use std::prelude::v1::*;
|
|||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
use num_traits::Float;
|
use num_traits::Float;
|
||||||
|
|
||||||
#[inline]
|
#[cold]
|
||||||
|
#[inline(never)]
|
||||||
pub fn make_err(msg: impl Into<String>) -> RhaiError {
|
pub fn make_err(msg: impl Into<String>) -> RhaiError {
|
||||||
ERR::ErrorArithmetic(msg.into(), Position::NONE).into()
|
ERR::ErrorArithmetic(msg.into(), Position::NONE).into()
|
||||||
}
|
}
|
||||||
|
@ -120,11 +120,9 @@ pub trait Package {
|
|||||||
///
|
///
|
||||||
/// def_package! {
|
/// def_package! {
|
||||||
/// /// My super-duper package.
|
/// /// My super-duper package.
|
||||||
/// pub MyPackage(module @ 10) {
|
/// pub MyPackage(module) {
|
||||||
/// // Load a native Rust function.
|
/// // Load a native Rust function.
|
||||||
/// module.set_native_fn("my_add", add);
|
/// module.set_native_fn("my_add", add);
|
||||||
/// } |> |engine| {
|
|
||||||
/// engine.register_custom_operator("@", 160).unwrap();
|
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -249,6 +249,7 @@ impl fmt::Display for EvalAltResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T: AsRef<str>> From<T> for EvalAltResult {
|
impl<T: AsRef<str>> From<T> for EvalAltResult {
|
||||||
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn from(err: T) -> Self {
|
fn from(err: T) -> Self {
|
||||||
Self::ErrorRuntime(err.as_ref().to_string().into(), Position::NONE)
|
Self::ErrorRuntime(err.as_ref().to_string().into(), Position::NONE)
|
||||||
@ -256,6 +257,7 @@ impl<T: AsRef<str>> From<T> for EvalAltResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T: AsRef<str>> From<T> for Box<EvalAltResult> {
|
impl<T: AsRef<str>> From<T> for Box<EvalAltResult> {
|
||||||
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn from(err: T) -> Self {
|
fn from(err: T) -> Self {
|
||||||
EvalAltResult::ErrorRuntime(err.as_ref().to_string().into(), Position::NONE).into()
|
EvalAltResult::ErrorRuntime(err.as_ref().to_string().into(), Position::NONE).into()
|
||||||
@ -266,6 +268,8 @@ impl EvalAltResult {
|
|||||||
/// Is this a pseudo error? A pseudo error is one that does not occur naturally.
|
/// Is this a pseudo error? A pseudo error is one that does not occur naturally.
|
||||||
///
|
///
|
||||||
/// [`LoopBreak`][EvalAltResult::LoopBreak] and [`Return`][EvalAltResult::Return] are pseudo errors.
|
/// [`LoopBreak`][EvalAltResult::LoopBreak] and [`Return`][EvalAltResult::Return] are pseudo errors.
|
||||||
|
#[cold]
|
||||||
|
#[inline(never)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_pseudo_error(&self) -> bool {
|
pub const fn is_pseudo_error(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -274,6 +278,8 @@ impl EvalAltResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Can this error be caught?
|
/// Can this error be caught?
|
||||||
|
#[cold]
|
||||||
|
#[inline(never)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_catchable(&self) -> bool {
|
pub const fn is_catchable(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -319,6 +325,8 @@ impl EvalAltResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Is this error a system exception?
|
/// Is this error a system exception?
|
||||||
|
#[cold]
|
||||||
|
#[inline(never)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn is_system_exception(&self) -> bool {
|
pub const fn is_system_exception(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -338,6 +346,8 @@ impl EvalAltResult {
|
|||||||
}
|
}
|
||||||
/// Get the [position][Position] of this error.
|
/// Get the [position][Position] of this error.
|
||||||
#[cfg(not(feature = "no_object"))]
|
#[cfg(not(feature = "no_object"))]
|
||||||
|
#[cold]
|
||||||
|
#[inline(never)]
|
||||||
pub(crate) fn dump_fields(&self, map: &mut crate::Map) {
|
pub(crate) fn dump_fields(&self, map: &mut crate::Map) {
|
||||||
map.insert(
|
map.insert(
|
||||||
"error".into(),
|
"error".into(),
|
||||||
@ -419,6 +429,8 @@ impl EvalAltResult {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
/// Unwrap this error and get the very base error.
|
/// Unwrap this error and get the very base error.
|
||||||
|
#[cold]
|
||||||
|
#[inline(never)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn unwrap_inner(&self) -> &Self {
|
pub fn unwrap_inner(&self) -> &Self {
|
||||||
match self {
|
match self {
|
||||||
@ -429,6 +441,8 @@ impl EvalAltResult {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Get the [position][Position] of this error.
|
/// Get the [position][Position] of this error.
|
||||||
|
#[cold]
|
||||||
|
#[inline(never)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn position(&self) -> Position {
|
pub const fn position(&self) -> Position {
|
||||||
match self {
|
match self {
|
||||||
@ -470,18 +484,24 @@ impl EvalAltResult {
|
|||||||
/// Remove the [position][Position] information from this error.
|
/// Remove the [position][Position] information from this error.
|
||||||
///
|
///
|
||||||
/// The [position][Position] of this error is set to [`NONE`][Position::NONE] afterwards.
|
/// The [position][Position] of this error is set to [`NONE`][Position::NONE] afterwards.
|
||||||
|
#[cold]
|
||||||
|
#[inline(never)]
|
||||||
pub fn clear_position(&mut self) -> &mut Self {
|
pub fn clear_position(&mut self) -> &mut Self {
|
||||||
self.set_position(Position::NONE)
|
self.set_position(Position::NONE)
|
||||||
}
|
}
|
||||||
/// Remove the [position][Position] information from this error and return it.
|
/// Remove the [position][Position] information from this error and return it.
|
||||||
///
|
///
|
||||||
/// The [position][Position] of this error is set to [`NONE`][Position::NONE] afterwards.
|
/// The [position][Position] of this error is set to [`NONE`][Position::NONE] afterwards.
|
||||||
|
#[cold]
|
||||||
|
#[inline(never)]
|
||||||
pub fn take_position(&mut self) -> Position {
|
pub fn take_position(&mut self) -> Position {
|
||||||
let pos = self.position();
|
let pos = self.position();
|
||||||
self.set_position(Position::NONE);
|
self.set_position(Position::NONE);
|
||||||
pos
|
pos
|
||||||
}
|
}
|
||||||
/// Override the [position][Position] of this error.
|
/// Override the [position][Position] of this error.
|
||||||
|
#[cold]
|
||||||
|
#[inline(never)]
|
||||||
pub fn set_position(&mut self, new_position: Position) -> &mut Self {
|
pub fn set_position(&mut self, new_position: Position) -> &mut Self {
|
||||||
match self {
|
match self {
|
||||||
Self::ErrorSystem(..) => (),
|
Self::ErrorSystem(..) => (),
|
||||||
@ -522,6 +542,7 @@ impl EvalAltResult {
|
|||||||
}
|
}
|
||||||
/// Consume the current [`EvalAltResult`] and return a new one with the specified [`Position`]
|
/// Consume the current [`EvalAltResult`] and return a new one with the specified [`Position`]
|
||||||
/// if the current position is [`Position::NONE`].
|
/// if the current position is [`Position::NONE`].
|
||||||
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub(crate) fn fill_position(mut self: Box<Self>, new_position: Position) -> Box<Self> {
|
pub(crate) fn fill_position(mut self: Box<Self>, new_position: Position) -> Box<Self> {
|
||||||
|
@ -263,6 +263,7 @@ impl fmt::Display for ParseErrorType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl From<LexError> for ParseErrorType {
|
impl From<LexError> for ParseErrorType {
|
||||||
|
#[cold]
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
fn from(err: LexError) -> Self {
|
fn from(err: LexError) -> Self {
|
||||||
match err {
|
match err {
|
||||||
@ -300,13 +301,15 @@ impl fmt::Display for ParseError {
|
|||||||
|
|
||||||
impl ParseError {
|
impl ParseError {
|
||||||
/// Get the [type][ParseErrorType] of this parse error.
|
/// Get the [type][ParseErrorType] of this parse error.
|
||||||
#[inline(always)]
|
#[cold]
|
||||||
|
#[inline(never)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn err_type(&self) -> &ParseErrorType {
|
pub const fn err_type(&self) -> &ParseErrorType {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
/// Get the [position][Position] of this parse error.
|
/// Get the [position][Position] of this parse error.
|
||||||
#[inline(always)]
|
#[cold]
|
||||||
|
#[inline(never)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub const fn position(&self) -> Position {
|
pub const fn position(&self) -> Position {
|
||||||
self.1
|
self.1
|
||||||
@ -314,28 +317,32 @@ impl ParseError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl From<ParseErrorType> for RhaiError {
|
impl From<ParseErrorType> for RhaiError {
|
||||||
#[inline(always)]
|
#[cold]
|
||||||
|
#[inline(never)]
|
||||||
fn from(err: ParseErrorType) -> Self {
|
fn from(err: ParseErrorType) -> Self {
|
||||||
Box::new(err.into())
|
Box::new(err.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ParseErrorType> for ERR {
|
impl From<ParseErrorType> for ERR {
|
||||||
#[inline(always)]
|
#[cold]
|
||||||
|
#[inline(never)]
|
||||||
fn from(err: ParseErrorType) -> Self {
|
fn from(err: ParseErrorType) -> Self {
|
||||||
Self::ErrorParsing(err, Position::NONE)
|
Self::ErrorParsing(err, Position::NONE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ParseError> for RhaiError {
|
impl From<ParseError> for RhaiError {
|
||||||
#[inline(always)]
|
#[cold]
|
||||||
|
#[inline(never)]
|
||||||
fn from(err: ParseError) -> Self {
|
fn from(err: ParseError) -> Self {
|
||||||
Box::new(err.into())
|
Box::new(err.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ParseError> for ERR {
|
impl From<ParseError> for ERR {
|
||||||
#[inline(always)]
|
#[cold]
|
||||||
|
#[inline(never)]
|
||||||
fn from(err: ParseError) -> Self {
|
fn from(err: ParseError) -> Self {
|
||||||
Self::ErrorParsing(*err.0, err.1)
|
Self::ErrorParsing(*err.0, err.1)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user