git.delta.rocks / jrsonnet / refs/commits / 8d39c73a8cfc

difftreelog

perf inline NumValue methods

Yaroslav Bolyukin2024-05-27parent: #afca77d.patch.diff
in: master

3 files changed

modifiedcrates/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)) => {
modifiedcrates/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)
 	}
modifiednix/jrsonnet.nixdiffbeforeafterboth
before · nix/jrsonnet.nix
1{2  lib,3  craneLib,4  makeWrapper,5  withNightlyFeatures ? false,6  withExperimentalFeatures ? false,7  forBenchmarks ? false,8}:9with lib;10  craneLib.buildPackage {11    src = lib.cleanSourceWith {12      src = ../.;13      filter = path: type:14        (lib.hasSuffix "\.jsonnet" path)15        || (craneLib.filterCargoSources path type);16    };17    pname = "jrsonnet";18    version = "current${optionalString withNightlyFeatures "-nightly"}${optionalString withExperimentalFeatures "-experimental"}";1920    cargoExtraArgs = "--locked --features=mimalloc,legacy-this-file${optionalString withNightlyFeatures ",nightly"}${optionalString withExperimentalFeatures ",experimental"}";2122    nativeBuildInputs = [makeWrapper];2324    # To clean-up hyperfine output25    postInstall = optionalString forBenchmarks ''26      wrapProgram $out/bin/jrsonnet --add-flags "--max-stack=200000 --os-stack=200000"27    '';28  }