difftreelog
perf move deepJoin to native
in: master
3 files changed
crates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/arrays.rs
+++ b/crates/jrsonnet-stdlib/src/arrays.rs
@@ -204,10 +204,31 @@
pub fn builtin_lines(arr: ArrValue) -> Result<IndexableVal> {
builtin_join(
IndexableVal::Str("\n".into()),
- ArrValue::extended(arr, ArrValue::eager(vec![Val::string("")])).into(),
+ ArrValue::extended(arr, ArrValue::eager(vec![Val::string("")])),
)
}
+pub fn deep_join_inner(out: &mut String, arr: IndexableVal) -> Result<()> {
+ use std::fmt::Write;
+ match arr {
+ IndexableVal::Str(s) => write!(out, "{s}").expect("no error"),
+ IndexableVal::Arr(arr) => {
+ for ele in arr.iter() {
+ let indexable = IndexableVal::from_untyped(ele?)?;
+ deep_join_inner(out, indexable)?;
+ }
+ }
+ }
+ Ok(())
+}
+
+#[builtin]
+pub fn builtin_deep_join(arr: IndexableVal) -> Result<String> {
+ let mut out = String::new();
+ deep_join_inner(&mut out, arr)?;
+ Ok(out)
+}
+
#[builtin]
pub fn builtin_reverse(arr: ArrValue) -> ArrValue {
arr.reversed()
crates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth86 ("range", builtin_range::INST),86 ("range", builtin_range::INST),87 ("join", builtin_join::INST),87 ("join", builtin_join::INST),88 ("lines", builtin_lines::INST),88 ("lines", builtin_lines::INST),89 ("deepJoin", builtin_deep_join::INST),89 ("reverse", builtin_reverse::INST),90 ("reverse", builtin_reverse::INST),90 ("any", builtin_any::INST),91 ("any", builtin_any::INST),91 ("all", builtin_all::INST),92 ("all", builtin_all::INST),crates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/std.jsonnet
+++ b/crates/jrsonnet-stdlib/src/std.jsonnet
@@ -11,14 +11,6 @@
else
{ [k]: func(k, obj[k]) for k in std.objectFields(obj) },
- deepJoin(arr)::
- if std.isString(arr) then
- arr
- else if std.isArray(arr) then
- std.join('', [std.deepJoin(x) for x in arr])
- else
- error 'Expected string or array, got %s' % std.type(arr),
-
assertEqual(a, b)::
if a == b then
true