git.delta.rocks / jrsonnet / refs/commits / 6a2bca3d52a3

difftreelog

refactor no need to store multiple assertions for oopobject

kspzkpvkYaroslav Bolyukin2026-03-19parent: #a8b25fb.patch.diff
in: master

2 files changed

modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth
598 || bail!(RuntimeError(evaluate(ctx, e)?.to_string()?,)),598 || bail!(RuntimeError(evaluate(ctx, e)?.to_string()?,)),
599 )?,599 )?,
600 IfElse (if_else)600 IfElse(if_else) => {
601 // {
602 // cond,
603 // cond_then,
604 // cond_else,
605 // }
606 => {
607 if in_frame(601 if in_frame(
608 CallLocation::new(&loc),602 CallLocation::new(&loc),
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -151,7 +151,7 @@
 #[derive(Trace, Default)]
 #[trace(tracking(force))]
 pub struct OopObject {
-	assertions: Vec<CcObjectAssertion>,
+	assertion: Option<CcObjectAssertion>,
 	this_entries: FxHashMap<IStr, ObjMember>,
 }
 impl Debug for OopObject {
@@ -163,7 +163,7 @@
 }
 impl OopObject {
 	fn is_empty(&self) -> bool {
-		self.assertions.is_empty() && self.this_entries.is_empty()
+		self.assertion.is_none() && self.this_entries.is_empty()
 	}
 }
 
@@ -979,11 +979,11 @@
 impl OopObject {
 	pub fn new(
 		this_entries: FxHashMap<IStr, ObjMember>,
-		assertions: Vec<CcObjectAssertion>,
+		assertion: Option<CcObjectAssertion>,
 	) -> Self {
 		Self {
 			this_entries,
-			assertions,
+			assertion,
 		}
 	}
 }
@@ -1042,10 +1042,7 @@
 	}
 
 	fn run_assertions_core(&self, sup_this: SupThis) -> Result<()> {
-		if self.assertions.is_empty() {
-			return Ok(());
-		}
-		for assertion in self.assertions.iter() {
+		if let Some(assertion) = &self.assertion {
 			assertion.0.run(sup_this.clone())?;
 		}
 		Ok(())
@@ -1067,7 +1064,7 @@
 		Self {
 			sup: vec![],
 			new: OopObject {
-				assertions: vec![],
+				assertion: None,
 				this_entries: FxHashMap::with_capacity(capacity),
 			},
 			next_field_index: FieldIndex::default(),
@@ -1075,10 +1072,6 @@
 	}
 	pub fn reserve_cores(&mut self, capacity: usize) -> &mut Self {
 		self.sup.reserve_exact(capacity);
-		self
-	}
-	pub fn reserve_asserts(&mut self, capacity: usize) -> &mut Self {
-		self.new.assertions.reserve_exact(capacity);
 		self
 	}
 	pub fn with_super(&mut self, super_obj: ObjValue) -> &mut Self {
@@ -1087,7 +1080,11 @@
 	}
 
 	pub fn assert(&mut self, assertion: impl ObjectAssertion + 'static) -> &mut Self {
-		self.new.assertions.push(CcObjectAssertion::new(assertion));
+		assert!(
+			self.new.assertion.is_none(),
+			"one OopObject can only have one assertion"
+		);
+		self.new.assertion = Some(CcObjectAssertion::new(assertion));
 		self
 	}
 	pub fn field(&mut self, name: impl Into<IStr>) -> ObjMemberBuilder<ValueBuilder<'_>> {