git.delta.rocks / jrsonnet / refs/commits / 60b06d56f879

difftreelog

perf document iter_cheap vs iter

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

2 files changed

modifiedcrates/jrsonnet-evaluator/src/arr/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/arr/mod.rs
+++ b/crates/jrsonnet-evaluator/src/arr/mod.rs
@@ -145,6 +145,9 @@
 	}
 
 	/// Returns None if get is either non cheap, or out of bounds
+	/// Note that non-cheap access includes errorable values
+	///
+	/// Prefer it to `get_lazy`, but use `get` when you can.
 	fn get_cheap(&self, index: usize) -> Option<Val> {
 		self.0.get_cheap(index)
 	}
@@ -165,6 +168,7 @@
 		(0..self.len()).map(|i| self.get_lazy(i).expect("length checked"))
 	}
 
+	/// Prefer it over `iter_lazy`, but do not use it where `iter` will do.
 	pub fn iter_cheap(&self) -> Option<impl ArrayLikeIter<Val> + '_> {
 		if self.is_cheap() {
 			Some((0..self.len()).map(|i| self.get_cheap(i).expect("length and is_cheap checked")))
modifiedcrates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth
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)) => {
101 if let (Some(ai), Some(bi)) = (a.iter_cheap(), b.iter_cheap()) {
102 for (a, b) in ai.zip(bi) {
103 let ord = evaluate_compare_op(&a, &b, op)?;
104 if !ord.is_eq() {
105 return Ok(ord);
106 }
107 }
108 } else {
109 let ai = a.iter();101 let ai = a.iter();
110 let bi = b.iter();102 let bi = b.iter();
111103
115 return Ok(ord);107 return Ok(ord);
116 }108 }
117 }109 }
118 }
119 a.len().cmp(&b.len())110 a.len().cmp(&b.len())
120 }111 }
121 (_, _) => bail!(BinaryOperatorDoesNotOperateOnValues(112 (_, _) => bail!(BinaryOperatorDoesNotOperateOnValues(