From 12a8bf00c034d573b705671edd5c17d12592344c Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Sun, 19 May 2024 16:00:07 +0000 Subject: [PATCH] perf: move std.lines to native --- --- a/crates/jrsonnet-stdlib/src/arrays.rs +++ b/crates/jrsonnet-stdlib/src/arrays.rs @@ -201,6 +201,14 @@ } #[builtin] +pub fn builtin_lines(arr: ArrValue) -> Result { + builtin_join( + IndexableVal::Str("\n".into()), + ArrValue::extended(arr, ArrValue::eager(vec![Val::string("")])).into(), + ) +} + +#[builtin] pub fn builtin_reverse(arr: ArrValue) -> ArrValue { arr.reversed() } --- a/crates/jrsonnet-stdlib/src/lib.rs +++ b/crates/jrsonnet-stdlib/src/lib.rs @@ -85,6 +85,7 @@ ("foldr", builtin_foldr::INST), ("range", builtin_range::INST), ("join", builtin_join::INST), + ("lines", builtin_lines::INST), ("reverse", builtin_reverse::INST), ("any", builtin_any::INST), ("all", builtin_all::INST), --- a/crates/jrsonnet-stdlib/src/std.jsonnet +++ b/crates/jrsonnet-stdlib/src/std.jsonnet @@ -11,9 +11,6 @@ else { [k]: func(k, obj[k]) for k in std.objectFields(obj) }, - lines(arr):: - std.join('\n', arr + ['']), - deepJoin(arr):: if std.isString(arr) then arr -- gitstuff