difftreelog
perf move std.setInter to native
in: master
3 files changed
crates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -42,6 +42,8 @@
pub use misc::*;
mod sets;
pub use sets::*;
+mod compat;
+pub use compat::*;
pub fn stdlib_uncached(settings: Rc<RefCell<Settings>>) -> ObjValue {
let mut builder = ObjValueBuilder::new();
@@ -147,6 +149,7 @@
("endsWith", builtin_ends_with::INST),
// Sets
("setMember", builtin_set_member::INST),
+ ("setInter", builtin_set_inter::INST),
]
.iter()
.cloned()
crates/jrsonnet-stdlib/src/sets.rsdiffbeforeafterboth1use std::cmp::Ordering;23use jrsonnet_evaluator::{4 error::Result,5 function::{builtin, FuncVal},6 operator::evaluate_compare_op,7 val::ArrValue,8 Val,9};10use jrsonnet_parser::BinaryOpType;1112#[builtin]13#[allow(non_snake_case)]14pub fn builtin_set_member(x: Val, arr: ArrValue, keyF: Option<FuncVal>) -> Result<bool> {15 let mut low = 0;16 let mut high = arr.len();1718 let keyF = keyF.unwrap_or(FuncVal::Id).into_native::<((Val,), Val)>();1920 let x = keyF(x)?;2122 while low < high {23 let middle = (high + low) / 2;24 match evaluate_compare_op(&arr.get(middle)?.expect("in bounds"), &x, BinaryOpType::Lt)? {25 Ordering::Less => low = middle + 1,26 Ordering::Equal => return Ok(true),27 Ordering::Greater => high = middle,28 }29 }30 Ok(false)31}crates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/std.jsonnet
+++ b/crates/jrsonnet-stdlib/src/std.jsonnet
@@ -214,19 +214,6 @@
aux(a, b, i, j + 1, acc + [b[j]]) tailstrict;
aux(a, b, 0, 0, []),
- setInter(a, b, keyF=id)::
- local aux(a, b, i, j, acc) =
- if i >= std.length(a) || j >= std.length(b) then
- acc
- else
- if keyF(a[i]) == keyF(b[j]) then
- aux(a, b, i + 1, j + 1, acc + [a[i]]) tailstrict
- else if keyF(a[i]) < keyF(b[j]) then
- aux(a, b, i + 1, j, acc) tailstrict
- else
- aux(a, b, i, j + 1, acc) tailstrict;
- aux(a, b, 0, 0, []) tailstrict,
-
setDiff(a, b, keyF=id)::
local aux(a, b, i, j, acc) =
if i >= std.length(a) then