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
145 }145 }
146146
147 /// Returns None if get is either non cheap, or out of bounds147 /// Returns None if get is either non cheap, or out of bounds
148 /// Note that non-cheap access includes errorable values
149 ///
150 /// Prefer it to `get_lazy`, but use `get` when you can.
148 fn get_cheap(&self, index: usize) -> Option<Val> {151 fn get_cheap(&self, index: usize) -> Option<Val> {
149 self.0.get_cheap(index)152 self.0.get_cheap(index)
150 }153 }
165 (0..self.len()).map(|i| self.get_lazy(i).expect("length checked"))168 (0..self.len()).map(|i| self.get_lazy(i).expect("length checked"))
166 }169 }
167170
171 /// Prefer it over `iter_lazy`, but do not use it where `iter` will do.
168 pub fn iter_cheap(&self) -> Option<impl ArrayLikeIter<Val> + '_> {172 pub fn iter_cheap(&self) -> Option<impl ArrayLikeIter<Val> + '_> {
169 if self.is_cheap() {173 if self.is_cheap() {
170 Some((0..self.len()).map(|i| self.get_cheap(i).expect("length and is_cheap checked")))174 Some((0..self.len()).map(|i| self.get_cheap(i).expect("length and is_cheap checked")))
modifiedcrates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate/operator.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/operator.rs
@@ -98,22 +98,13 @@
 		#[cfg(feature = "exp-bigint")]
 		(BigInt(a), BigInt(b)) => a.cmp(b),
 		(Arr(a), Arr(b)) => {
-			if let (Some(ai), Some(bi)) = (a.iter_cheap(), b.iter_cheap()) {
-				for (a, b) in ai.zip(bi) {
-					let ord = evaluate_compare_op(&a, &b, op)?;
-					if !ord.is_eq() {
-						return Ok(ord);
-					}
-				}
-			} else {
-				let ai = a.iter();
-				let bi = b.iter();
+			let ai = a.iter();
+			let bi = b.iter();
 
-				for (a, b) in ai.zip(bi) {
-					let ord = evaluate_compare_op(&a?, &b?, op)?;
-					if !ord.is_eq() {
-						return Ok(ord);
-					}
+			for (a, b) in ai.zip(bi) {
+				let ord = evaluate_compare_op(&a?, &b?, op)?;
+				if !ord.is_eq() {
+					return Ok(ord);
 				}
 			}
 			a.len().cmp(&b.len())