difftreelog
perf move mapWithKey to native
in: master
3 files changed
crates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth6 runtime_error,6 runtime_error,7 typed::{BoundedI32, BoundedUsize, Either2, NativeFn, Typed},7 typed::{BoundedI32, BoundedUsize, Either2, NativeFn, Typed},8 val::{equals, ArrValue, IndexableVal},8 val::{equals, ArrValue, IndexableVal},9 Either, IStr, ObjValueBuilder, Result, ResultExt, Thunk, Val,9 Either, IStr, ObjValue, ObjValueBuilder, Result, ResultExt, Thunk, Val,10};10};111112pub fn eval_on_empty(on_empty: Option<Thunk<Val>>) -> Result<Val> {12pub fn eval_on_empty(on_empty: Option<Thunk<Val>>) -> Result<Val> {67 arr.map_with_index(func)67 arr.map_with_index(func)68}68}6970#[builtin]71pub fn builtin_map_with_key(func: FuncVal, obj: ObjValue) -> Result<ObjValue> {72 let mut out = ObjValueBuilder::new();73 for (k, v) in obj.iter() {74 let v = v?;75 out.field(k).value(func.evaluate_simple(&(v,), false)?);76 }77 Ok(out.build())78}697970#[builtin]80#[builtin]71pub fn builtin_flatmap(81pub fn builtin_flatmap(crates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth79 ("slice", builtin_slice::INST),79 ("slice", builtin_slice::INST),80 ("map", builtin_map::INST),80 ("map", builtin_map::INST),81 ("mapWithIndex", builtin_map_with_index::INST),81 ("mapWithIndex", builtin_map_with_index::INST),82 ("mapWithKey", builtin_map_with_key::INST),82 ("flatMap", builtin_flatmap::INST),83 ("flatMap", builtin_flatmap::INST),83 ("filter", builtin_filter::INST),84 ("filter", builtin_filter::INST),84 ("foldl", builtin_foldl::INST),85 ("foldl", builtin_foldl::INST),crates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth2 local std = self,2 local std = self,334 thisFile:: error 'std.thisFile is deprecated, to enable its support in jrsonnet - recompile it with "legacy-this-file" support.\nThis will slow down stdlib caching a bit, though',4 thisFile:: error 'std.thisFile is deprecated, to enable its support in jrsonnet - recompile it with "legacy-this-file" support.\nThis will slow down stdlib caching a bit, though',56 mapWithKey(func, obj)::7 if !std.isFunction(func) then8 error ('std.mapWithKey first param must be function, got ' + std.type(func))9 else if !std.isObject(obj) then10 error ('std.mapWithKey second param must be object, got ' + std.type(obj))11 else12 { [k]: func(k, obj[k]) for k in std.objectFields(obj) },13}5}146