From a59a4f447fa87f6dcf2663319b45246760722cd2 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 21 Apr 2018 14:02:17 -0700 Subject: [PATCH] Mark error construction as cold code --- src/error.rs | 6 ++++++ src/number.rs | 2 ++ src/value/de.rs | 1 + 3 files changed, 9 insertions(+) diff --git a/src/error.rs b/src/error.rs index 4ef9048..61636dc 100644 --- a/src/error.rs +++ b/src/error.rs @@ -264,6 +264,7 @@ pub enum ErrorCode { impl Error { // Not public API. Should be pub(crate). #[doc(hidden)] + #[cold] pub fn syntax(code: ErrorCode, line: usize, column: usize) -> Self { Error { err: Box::new(ErrorImpl { @@ -278,6 +279,7 @@ impl Error { // // Update `eager_json` crate when this function changes. #[doc(hidden)] + #[cold] pub fn io(error: io::Error) -> Self { Error { err: Box::new(ErrorImpl { @@ -290,6 +292,7 @@ impl Error { // Not public API. Should be pub(crate). #[doc(hidden)] + #[cold] pub fn fix_position(self, f: F) -> Self where F: FnOnce(ErrorCode) -> Error, @@ -391,6 +394,7 @@ impl Debug for Error { } impl de::Error for Error { + #[cold] fn custom(msg: T) -> Error { Error { err: Box::new(ErrorImpl { @@ -401,6 +405,7 @@ impl de::Error for Error { } } + #[cold] fn invalid_type(unexp: de::Unexpected, exp: &de::Expected) -> Self { if let de::Unexpected::Unit = unexp { Error::custom(format_args!("invalid type: null, expected {}", exp)) @@ -411,6 +416,7 @@ impl de::Error for Error { } impl ser::Error for Error { + #[cold] fn custom(msg: T) -> Error { Error { err: Box::new(ErrorImpl { diff --git a/src/number.rs b/src/number.rs index 0d4b089..8149ae3 100644 --- a/src/number.rs +++ b/src/number.rs @@ -748,6 +748,7 @@ impl Number { #[cfg(not(feature = "arbitrary_precision"))] // Not public API. Should be pub(crate). #[doc(hidden)] + #[cold] pub fn unexpected(&self) -> Unexpected { match self.n { N::PosInt(u) => Unexpected::Unsigned(u), @@ -759,6 +760,7 @@ impl Number { #[cfg(feature = "arbitrary_precision")] // Not public API. Should be pub(crate). #[doc(hidden)] + #[cold] pub fn unexpected(&self) -> Unexpected { Unexpected::Other("number") } diff --git a/src/value/de.rs b/src/value/de.rs index 8137c57..c56af7b 100644 --- a/src/value/de.rs +++ b/src/value/de.rs @@ -1409,6 +1409,7 @@ impl Value { serde::de::Error::invalid_type(self.unexpected(), exp) } + #[cold] fn unexpected(&self) -> Unexpected { match *self { Value::Null => Unexpected::Unit,