difftreelog
perf document iter_cheap vs iter
in: master
2 files changed
crates/jrsonnet-evaluator/src/arr/mod.rsdiffbeforeafterboth145 }145 }146146147 /// Returns None if get is either non cheap, or out of bounds147 /// Returns None if get is either non cheap, or out of bounds148 /// Note that non-cheap access includes errorable values149 ///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 }167170171 /// 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")))crates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth98 #[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();111103115 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(