Add #[cold] tags.

This commit is contained in:
Stephen Chung 2022-09-13 22:54:13 +08:00
parent 2458e05dcb
commit 396ec7df8a
8 changed files with 43 additions and 17 deletions

View File

@ -170,11 +170,8 @@ impl Engine {
keyword: impl AsRef<str>,
precedence: u8,
) -> Result<&mut Self, String> {
let precedence = Precedence::new(precedence);
if precedence.is_none() {
return Err("precedence cannot be zero".into());
}
let precedence =
Precedence::new(precedence).ok_or_else(|| "precedence cannot be zero".to_string())?;
let keyword = keyword.as_ref();
@ -213,7 +210,8 @@ impl Engine {
}
// Add to custom keywords
self.custom_keywords.insert(keyword.into(), precedence);
self.custom_keywords
.insert(keyword.into(), Some(precedence));
Ok(self)
}

View File

@ -238,6 +238,7 @@ impl Engine {
}
/// Make a `Box<`[`EvalAltResult<ErrorMismatchDataType>`][ERR::ErrorMismatchDataType]`>`.
#[cold]
#[inline(never)]
#[must_use]
pub(crate) fn make_type_mismatch_err<T>(&self, typ: &str, pos: Position) -> RhaiError {

View File

@ -79,7 +79,6 @@ impl Caches<'_> {
self.stack.last_mut().unwrap()
}
/// Push an empty function resolution cache onto the stack and make it current.
#[allow(dead_code)]
#[inline(always)]
pub fn push_fn_resolution_cache(&mut self) {
self.stack.push(Default::default());

View File

@ -35,6 +35,7 @@ impl Engine {
pos: Position,
level: usize,
) -> RhaiResult {
#[cold]
#[inline(never)]
fn make_error(
name: String,

View File

@ -9,7 +9,8 @@ use std::prelude::v1::*;
#[cfg(not(feature = "no_float"))]
use num_traits::Float;
#[inline]
#[cold]
#[inline(never)]
pub fn make_err(msg: impl Into<String>) -> RhaiError {
ERR::ErrorArithmetic(msg.into(), Position::NONE).into()
}

View File

@ -120,11 +120,9 @@ pub trait Package {
///
/// def_package! {
/// /// My super-duper package.
/// pub MyPackage(module @ 10) {
/// pub MyPackage(module) {
/// // Load a native Rust function.
/// module.set_native_fn("my_add", add);
/// } |> |engine| {
/// engine.register_custom_operator("@", 160).unwrap();
/// }
/// }
/// ```

View File

@ -249,6 +249,7 @@ impl fmt::Display for EvalAltResult {
}
impl<T: AsRef<str>> From<T> for EvalAltResult {
#[cold]
#[inline(never)]
fn from(err: T) -> Self {
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> {
#[cold]
#[inline(never)]
fn from(err: T) -> Self {
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.
///
/// [`LoopBreak`][EvalAltResult::LoopBreak] and [`Return`][EvalAltResult::Return] are pseudo errors.
#[cold]
#[inline(never)]
#[must_use]
pub const fn is_pseudo_error(&self) -> bool {
match self {
@ -274,6 +278,8 @@ impl EvalAltResult {
}
}
/// Can this error be caught?
#[cold]
#[inline(never)]
#[must_use]
pub const fn is_catchable(&self) -> bool {
match self {
@ -319,6 +325,8 @@ impl EvalAltResult {
}
}
/// Is this error a system exception?
#[cold]
#[inline(never)]
#[must_use]
pub const fn is_system_exception(&self) -> bool {
match self {
@ -338,6 +346,8 @@ impl EvalAltResult {
}
/// Get the [position][Position] of this error.
#[cfg(not(feature = "no_object"))]
#[cold]
#[inline(never)]
pub(crate) fn dump_fields(&self, map: &mut crate::Map) {
map.insert(
"error".into(),
@ -419,6 +429,8 @@ impl EvalAltResult {
};
}
/// Unwrap this error and get the very base error.
#[cold]
#[inline(never)]
#[must_use]
pub fn unwrap_inner(&self) -> &Self {
match self {
@ -429,6 +441,8 @@ impl EvalAltResult {
}
}
/// Get the [position][Position] of this error.
#[cold]
#[inline(never)]
#[must_use]
pub const fn position(&self) -> Position {
match self {
@ -470,18 +484,24 @@ impl EvalAltResult {
/// Remove the [position][Position] information from this error.
///
/// The [position][Position] of this error is set to [`NONE`][Position::NONE] afterwards.
#[cold]
#[inline(never)]
pub fn clear_position(&mut self) -> &mut Self {
self.set_position(Position::NONE)
}
/// Remove the [position][Position] information from this error and return it.
///
/// The [position][Position] of this error is set to [`NONE`][Position::NONE] afterwards.
#[cold]
#[inline(never)]
pub fn take_position(&mut self) -> Position {
let pos = self.position();
self.set_position(Position::NONE);
pos
}
/// Override the [position][Position] of this error.
#[cold]
#[inline(never)]
pub fn set_position(&mut self, new_position: Position) -> &mut Self {
match self {
Self::ErrorSystem(..) => (),
@ -522,6 +542,7 @@ impl EvalAltResult {
}
/// Consume the current [`EvalAltResult`] and return a new one with the specified [`Position`]
/// if the current position is [`Position::NONE`].
#[cold]
#[inline(never)]
#[must_use]
pub(crate) fn fill_position(mut self: Box<Self>, new_position: Position) -> Box<Self> {

View File

@ -263,6 +263,7 @@ impl fmt::Display for ParseErrorType {
}
impl From<LexError> for ParseErrorType {
#[cold]
#[inline(never)]
fn from(err: LexError) -> Self {
match err {
@ -300,13 +301,15 @@ impl fmt::Display for ParseError {
impl ParseError {
/// Get the [type][ParseErrorType] of this parse error.
#[inline(always)]
#[cold]
#[inline(never)]
#[must_use]
pub const fn err_type(&self) -> &ParseErrorType {
&self.0
}
/// Get the [position][Position] of this parse error.
#[inline(always)]
#[cold]
#[inline(never)]
#[must_use]
pub const fn position(&self) -> Position {
self.1
@ -314,28 +317,32 @@ impl ParseError {
}
impl From<ParseErrorType> for RhaiError {
#[inline(always)]
#[cold]
#[inline(never)]
fn from(err: ParseErrorType) -> Self {
Box::new(err.into())
}
}
impl From<ParseErrorType> for ERR {
#[inline(always)]
#[cold]
#[inline(never)]
fn from(err: ParseErrorType) -> Self {
Self::ErrorParsing(err, Position::NONE)
}
}
impl From<ParseError> for RhaiError {
#[inline(always)]
#[cold]
#[inline(never)]
fn from(err: ParseError) -> Self {
Box::new(err.into())
}
}
impl From<ParseError> for ERR {
#[inline(always)]
#[cold]
#[inline(never)]
fn from(err: ParseError) -> Self {
Self::ErrorParsing(*err.0, err.1)
}