difftreelog
perf faster std.map
in: master
3 files changed
crates/jrsonnet-evaluator/build.rsdiffbeforeafterboth40 name == "base64" || name == "foldl" || name == "foldr" ||40 name == "base64" || name == "foldl" || name == "foldr" ||41 name == "sortImpl" || name == "format" || name == "range" ||41 name == "sortImpl" || name == "format" || name == "range" ||42 name == "reverse" || name == "slice" || name == "mod" ||42 name == "reverse" || name == "slice" || name == "mod" ||43 name == "strReplace"43 name == "strReplace" || name == "map"44 )44 )45 })45 })46 .collect(),46 .collect(),crates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth57 ("extVar".into(), builtin_ext_var),57 ("extVar".into(), builtin_ext_var),58 ("native".into(), builtin_native),58 ("native".into(), builtin_native),59 ("filter".into(), builtin_filter),59 ("filter".into(), builtin_filter),60 ("map".into(), builtin_map),60 ("foldl".into(), builtin_foldl),61 ("foldl".into(), builtin_foldl),61 ("foldr".into(), builtin_foldr),62 ("foldr".into(), builtin_foldr),62 ("sortImpl".into(), builtin_sort_impl),63 ("sortImpl".into(), builtin_sort_impl),294 0, func: ty!(function) => Val::Func;295 0, func: ty!(function) => Val::Func;295 1, arr: ty!(array) => Val::Arr;296 1, arr: ty!(array) => Val::Arr;296 ], {297 ], {297 let mut out = Vec::new();298 Ok(Val::Arr(arr.filter(|val| func298 for item in arr.iter() {299 let item = item?;300 if func301 .evaluate_values(context.clone(), &[item.clone()])?299 .evaluate_values(context.clone(), &[val.clone()])?302 .try_cast_bool("filter predicate")? {300 .try_cast_bool("filter predicate"))?))303 out.push(item);304 }305 }306 Ok(Val::Arr(out.into()))307 })301 })308}302}303304fn builtin_map(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {305 parse_args!(context, "map", args, 2, [306 0, func: ty!(function) => Val::Func;307 1, arr: ty!(array) => Val::Arr;308 ], {309 Ok(Val::Arr(arr.map(|val| func310 .evaluate_values(context.clone(), &[val]))?))311 })312}309313310fn builtin_foldl(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {314fn builtin_foldl(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {311 parse_args!(context, "foldl", args, 3, [315 parse_args!(context, "foldl", args, 3, [crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth283 }283 }284 }284 }285286 pub fn map(self, mapper: impl Fn(Val) -> Result<Val>) -> Result<Self> {287 let mut out = Vec::with_capacity(self.len());288289 for value in self.iter() {290 out.push(mapper(value?)?);291 }292293 Ok(Self::Eager(Rc::new(out)))294 }295296 pub fn filter(self, filter: impl Fn(&Val) -> Result<bool>) -> Result<Self> {297 let mut out = Vec::with_capacity(self.len());298299 for value in self.iter() {300 let value = value?;301 if filter(&value)? {302 out.push(value);303 }304 }305306 Ok(Self::Eager(Rc::new(out)))307 }285308286 pub fn ptr_eq(a: &Self, b: &Self) -> bool {309 pub fn ptr_eq(a: &Self, b: &Self) -> bool {287 match (a, b) {310 match (a, b) {