difftreelog
perf inline NumValue methods
in: master
3 files changed
crates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/operator.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/operator.rs
@@ -94,7 +94,7 @@
use Val::*;
Ok(match (a, b) {
(Str(a), Str(b)) => a.cmp(b),
- (Num(a), Num(b)) => a.partial_cmp(b).expect("jsonnet numbers are non NaN"),
+ (Num(a), Num(b)) => a.cmp(b),
#[cfg(feature = "exp-bigint")]
(BigInt(a), BigInt(b)) => a.cmp(b),
(Arr(a), Arr(b)) => {
crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -409,6 +409,7 @@
}
Some(Self(v))
}
+ #[inline]
pub const fn get(&self) -> f64 {
self.0
}
@@ -420,13 +421,15 @@
}
impl Eq for NumValue {}
impl Ord for NumValue {
+ #[inline]
fn cmp(&self, other: &Self) -> Ordering {
// Can't use `total_cmp`: its behavior for `-0` and `0`
// is not following wanted.
- self.0.partial_cmp(&other.0).expect("NaNs are disallowed")
+ unsafe { self.0.partial_cmp(&other.0).unwrap_unchecked() }
}
}
impl PartialOrd for NumValue {
+ #[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
@@ -439,6 +442,7 @@
impl Deref for NumValue {
type Target = f64;
+ #[inline]
fn deref(&self) -> &Self::Target {
&self.0
}
@@ -446,6 +450,7 @@
macro_rules! impl_num {
($($ty:ty),+) => {$(
impl From<$ty> for NumValue {
+ #[inline]
fn from(value: $ty) -> Self {
Self(value.into())
}
@@ -473,6 +478,7 @@
($($ty:ty),+) => {$(
impl TryFrom<$ty> for NumValue {
type Error = ConvertNumValueError;
+ #[inline]
fn try_from(value: $ty) -> Result<Self, ConvertNumValueError> {
use crate::typed::conversions::{MIN_SAFE_INTEGER, MAX_SAFE_INTEGER};
let value = value as f64;
@@ -492,6 +498,7 @@
impl TryFrom<f64> for NumValue {
type Error = ConvertNumValueError;
+ #[inline]
fn try_from(value: f64) -> Result<Self, Self::Error> {
Self::new(value).ok_or(ConvertNumValueError::NonFinite)
}
@@ -499,6 +506,7 @@
impl TryFrom<f32> for NumValue {
type Error = ConvertNumValueError;
+ #[inline]
fn try_from(value: f32) -> Result<Self, Self::Error> {
Self::new(f64::from(value)).ok_or(ConvertNumValueError::NonFinite)
}
nix/jrsonnet.nixdiffbeforeafterboth17 pname = "jrsonnet";17 pname = "jrsonnet";18 version = "current${optionalString withNightlyFeatures "-nightly"}${optionalString withExperimentalFeatures "-experimental"}";18 version = "current${optionalString withNightlyFeatures "-nightly"}${optionalString withExperimentalFeatures "-experimental"}";191920 cargoExtraArgs = "--locked --features=mimalloc,legacy-this-file${optionalString withNightlyFeatures ",nightly"}${optionalString withExperimentalFeatures ",experimental"}";20 cargoExtraArgs = "--locked --features=mimalloc${optionalString withNightlyFeatures ",nightly"}${optionalString withExperimentalFeatures ",experimental"}";212122 nativeBuildInputs = [makeWrapper];22 nativeBuildInputs = [makeWrapper];2323