From 3d527a7bcaaff8ef85f35f4e8c97a4bf92d5f099 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Tue, 12 Jan 2021 03:58:15 +0000 Subject: [PATCH] perf: use pointer equality in std.equals --- --- a/crates/jrsonnet-evaluator/src/obj.rs +++ b/crates/jrsonnet-evaluator/src/obj.rs @@ -139,6 +139,10 @@ .evaluate(Some(real_this.clone()), self.0.super_obj.clone())? .evaluate()?) } + + pub fn ptr_eq(a: &ObjValue, b: &ObjValue) -> bool { + Rc::ptr_eq(&a.0, &b.0) + } } impl PartialEq for ObjValue { fn eq(&self, other: &Self) -> bool { --- 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> 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); -- gitstuff