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
151#[derive(Trace, Default)]151#[derive(Trace, Default)]
152#[trace(tracking(force))]152#[trace(tracking(force))]
153pub struct OopObject {153pub struct OopObject {
154 assertions: Vec<CcObjectAssertion>,154 assertion: Option<CcObjectAssertion>,
155 this_entries: FxHashMap<IStr, ObjMember>,155 this_entries: FxHashMap<IStr, ObjMember>,
156}156}
157impl Debug for OopObject {157impl Debug for OopObject {
163}163}
164impl OopObject {164impl OopObject {
165 fn is_empty(&self) -> bool {165 fn is_empty(&self) -> bool {
166 self.assertions.is_empty() && self.this_entries.is_empty()166 self.assertion.is_none() && self.this_entries.is_empty()
167 }167 }
168}168}
169169
979impl OopObject {979impl OopObject {
980 pub fn new(980 pub fn new(
981 this_entries: FxHashMap<IStr, ObjMember>,981 this_entries: FxHashMap<IStr, ObjMember>,
982 assertions: Vec<CcObjectAssertion>,982 assertion: Option<CcObjectAssertion>,
983 ) -> Self {983 ) -> Self {
984 Self {984 Self {
985 this_entries,985 this_entries,
986 assertions,986 assertion,
987 }987 }
988 }988 }
989}989}
1042 }1042 }
10431043
1044 fn run_assertions_core(&self, sup_this: SupThis) -> Result<()> {1044 fn run_assertions_core(&self, sup_this: SupThis) -> Result<()> {
1045 if self.assertions.is_empty() {1045 if let Some(assertion) = &self.assertion {
1046 return Ok(());
1047 }
1048 for assertion in self.assertions.iter() {
1049 assertion.0.run(sup_this.clone())?;1046 assertion.0.run(sup_this.clone())?;
1050 }1047 }
1051 Ok(())1048 Ok(())
1067 Self {1064 Self {
1068 sup: vec![],1065 sup: vec![],
1069 new: OopObject {1066 new: OopObject {
1070 assertions: vec![],1067 assertion: None,
1071 this_entries: FxHashMap::with_capacity(capacity),1068 this_entries: FxHashMap::with_capacity(capacity),
1072 },1069 },
1073 next_field_index: FieldIndex::default(),1070 next_field_index: FieldIndex::default(),
1077 self.sup.reserve_exact(capacity);1074 self.sup.reserve_exact(capacity);
1078 self1075 self
1079 }1076 }
1080 pub fn reserve_asserts(&mut self, capacity: usize) -> &mut Self {
1081 self.new.assertions.reserve_exact(capacity);
1082 self
1083 }
1084 pub fn with_super(&mut self, super_obj: ObjValue) -> &mut Self {1077 pub fn with_super(&mut self, super_obj: ObjValue) -> &mut Self {
1085 self.sup = super_obj.0.cores.clone();1078 self.sup = super_obj.0.cores.clone();
1086 self1079 self
1087 }1080 }
10881081
1089 pub fn assert(&mut self, assertion: impl ObjectAssertion + 'static) -> &mut Self {1082 pub fn assert(&mut self, assertion: impl ObjectAssertion + 'static) -> &mut Self {
1083 assert!(
1084 self.new.assertion.is_none(),
1085 "one OopObject can only have one assertion"
1086 );
1090 self.new.assertions.push(CcObjectAssertion::new(assertion));1087 self.new.assertion = Some(CcObjectAssertion::new(assertion));
1091 self1088 self
1092 }1089 }
1093 pub fn field(&mut self, name: impl Into<IStr>) -> ObjMemberBuilder<ValueBuilder<'_>> {1090 pub fn field(&mut self, name: impl Into<IStr>) -> ObjMemberBuilder<ValueBuilder<'_>> {