git.delta.rocks / jrsonnet / refs/commits / 3d527a7bcaaf

difftreelog

perf use pointer equality in std.equals

Yaroslav Bolyukin2021-01-12parent: #c214d99.patch.diff
in: master

2 files changed

modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
140 .evaluate()?)140 .evaluate()?)
141 }141 }
142
143 pub fn ptr_eq(a: &ObjValue, b: &ObjValue) -> bool {
144 Rc::ptr_eq(&a.0, &b.0)
145 }
142}146}
143impl PartialEq for ObjValue {147impl PartialEq for ObjValue {
144 fn eq(&self, other: &Self) -> bool {148 fn eq(&self, other: &Self) -> bool {
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -253,6 +253,14 @@
 			}
 		}
 	}
+
+	pub fn ptr_eq(a: &ArrValue, b: &ArrValue) -> bool {
+		match (a, b) {
+			(ArrValue::Lazy(a), ArrValue::Lazy(b)) => Rc::ptr_eq(a, b),
+			(ArrValue::Eager(a), ArrValue::Eager(b)) => Rc::ptr_eq(a, b),
+			_ => false,
+		}
+	}
 }
 
 impl From<Vec<LazyVal>> for ArrValue {
@@ -533,8 +541,10 @@
 		return Ok(false);
 	}
 	match (val_a, val_b) {
-		// Cant test for ptr equality, because all fields needs to be evaluated
 		(Val::Arr(a), Val::Arr(b)) => {
+			if ArrValue::ptr_eq(a, b) {
+				return Ok(true);
+			}
 			if a.len() != b.len() {
 				return Ok(false);
 			}
@@ -546,6 +556,9 @@
 			Ok(true)
 		}
 		(Val::Obj(a), Val::Obj(b)) => {
+			if ObjValue::ptr_eq(a, b) {
+				return Ok(true);
+			}
 			let fields = a.visible_fields();
 			if fields != b.visible_fields() {
 				return Ok(false);