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

difftreelog

perf inline NumValue methods

Yaroslav Bolyukin2024-06-18parent: #afca77d.patch.diff
in: master

3 files changed

modifiedcrates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth
94 use Val::*;94 use Val::*;
95 Ok(match (a, b) {95 Ok(match (a, b) {
96 (Str(a), Str(b)) => a.cmp(b),96 (Str(a), Str(b)) => a.cmp(b),
97 (Num(a), Num(b)) => a.partial_cmp(b).expect("jsonnet numbers are non NaN"),97 (Num(a), Num(b)) => a.cmp(b),
98 #[cfg(feature = "exp-bigint")]98 #[cfg(feature = "exp-bigint")]
99 (BigInt(a), BigInt(b)) => a.cmp(b),99 (BigInt(a), BigInt(b)) => a.cmp(b),
100 (Arr(a), Arr(b)) => {100 (Arr(a), Arr(b)) => {
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
409 }409 }
410 Some(Self(v))410 Some(Self(v))
411 }411 }
412 #[inline]
412 pub const fn get(&self) -> f64 {413 pub const fn get(&self) -> f64 {
413 self.0414 self.0
414 }415 }
420}421}
421impl Eq for NumValue {}422impl Eq for NumValue {}
422impl Ord for NumValue {423impl Ord for NumValue {
424 #[inline]
423 fn cmp(&self, other: &Self) -> Ordering {425 fn cmp(&self, other: &Self) -> Ordering {
424 // Can't use `total_cmp`: its behavior for `-0` and `0`426 // Can't use `total_cmp`: its behavior for `-0` and `0`
425 // is not following wanted.427 // is not following wanted.
426 self.0.partial_cmp(&other.0).expect("NaNs are disallowed")428 unsafe { self.0.partial_cmp(&other.0).unwrap_unchecked() }
427 }429 }
428}430}
429impl PartialOrd for NumValue {431impl PartialOrd for NumValue {
432 #[inline]
430 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {433 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
431 Some(self.cmp(other))434 Some(self.cmp(other))
432 }435 }
439impl Deref for NumValue {442impl Deref for NumValue {
440 type Target = f64;443 type Target = f64;
441444
445 #[inline]
442 fn deref(&self) -> &Self::Target {446 fn deref(&self) -> &Self::Target {
443 &self.0447 &self.0
444 }448 }
445}449}
446macro_rules! impl_num {450macro_rules! impl_num {
447 ($($ty:ty),+) => {$(451 ($($ty:ty),+) => {$(
448 impl From<$ty> for NumValue {452 impl From<$ty> for NumValue {
453 #[inline]
449 fn from(value: $ty) -> Self {454 fn from(value: $ty) -> Self {
450 Self(value.into())455 Self(value.into())
451 }456 }
473 ($($ty:ty),+) => {$(478 ($($ty:ty),+) => {$(
474 impl TryFrom<$ty> for NumValue {479 impl TryFrom<$ty> for NumValue {
475 type Error = ConvertNumValueError;480 type Error = ConvertNumValueError;
481 #[inline]
476 fn try_from(value: $ty) -> Result<Self, ConvertNumValueError> {482 fn try_from(value: $ty) -> Result<Self, ConvertNumValueError> {
477 use crate::typed::conversions::{MIN_SAFE_INTEGER, MAX_SAFE_INTEGER};483 use crate::typed::conversions::{MIN_SAFE_INTEGER, MAX_SAFE_INTEGER};
478 let value = value as f64;484 let value = value as f64;
492impl TryFrom<f64> for NumValue {498impl TryFrom<f64> for NumValue {
493 type Error = ConvertNumValueError;499 type Error = ConvertNumValueError;
494500
501 #[inline]
495 fn try_from(value: f64) -> Result<Self, Self::Error> {502 fn try_from(value: f64) -> Result<Self, Self::Error> {
496 Self::new(value).ok_or(ConvertNumValueError::NonFinite)503 Self::new(value).ok_or(ConvertNumValueError::NonFinite)
497 }504 }
498}505}
499impl TryFrom<f32> for NumValue {506impl TryFrom<f32> for NumValue {
500 type Error = ConvertNumValueError;507 type Error = ConvertNumValueError;
501508
509 #[inline]
502 fn try_from(value: f32) -> Result<Self, Self::Error> {510 fn try_from(value: f32) -> Result<Self, Self::Error> {
503 Self::new(f64::from(value)).ok_or(ConvertNumValueError::NonFinite)511 Self::new(f64::from(value)).ok_or(ConvertNumValueError::NonFinite)
504 }512 }
modifiednix/jrsonnet.nixdiffbeforeafterboth
17 pname = "jrsonnet";17 pname = "jrsonnet";
18 version = "current${optionalString withNightlyFeatures "-nightly"}${optionalString withExperimentalFeatures "-experimental"}";18 version = "current${optionalString withNightlyFeatures "-nightly"}${optionalString withExperimentalFeatures "-experimental"}";
1919
20 cargoExtraArgs = "--locked --features=mimalloc,legacy-this-file${optionalString withNightlyFeatures ",nightly"}${optionalString withExperimentalFeatures ",experimental"}";20 cargoExtraArgs = "--locked --features=mimalloc${optionalString withNightlyFeatures ",nightly"}${optionalString withExperimentalFeatures ",experimental"}";
2121
22 nativeBuildInputs = [makeWrapper];22 nativeBuildInputs = [makeWrapper];
2323