git.delta.rocks / jrsonnet / refs/commits / f58bb8e97c94

difftreelog

perf move deepJoin to native

Yaroslav Bolyukin2024-06-18parent: #0e22242.patch.diff
in: master

3 files changed

modifiedcrates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth
204pub fn builtin_lines(arr: ArrValue) -> Result<IndexableVal> {204pub fn builtin_lines(arr: ArrValue) -> Result<IndexableVal> {
205 builtin_join(205 builtin_join(
206 IndexableVal::Str("\n".into()),206 IndexableVal::Str("\n".into()),
207 ArrValue::extended(arr, ArrValue::eager(vec![Val::string("")])).into(),207 ArrValue::extended(arr, ArrValue::eager(vec![Val::string("")])),
208 )208 )
209}209}
210
211pub fn deep_join_inner(out: &mut String, arr: IndexableVal) -> Result<()> {
212 use std::fmt::Write;
213 match arr {
214 IndexableVal::Str(s) => write!(out, "{s}").expect("no error"),
215 IndexableVal::Arr(arr) => {
216 for ele in arr.iter() {
217 let indexable = IndexableVal::from_untyped(ele?)?;
218 deep_join_inner(out, indexable)?;
219 }
220 }
221 }
222 Ok(())
223}
224
225#[builtin]
226pub fn builtin_deep_join(arr: IndexableVal) -> Result<String> {
227 let mut out = String::new();
228 deep_join_inner(&mut out, arr)?;
229 Ok(out)
230}
210231
211#[builtin]232#[builtin]
212pub fn builtin_reverse(arr: ArrValue) -> ArrValue {233pub fn builtin_reverse(arr: ArrValue) -> ArrValue {
modifiedcrates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -86,6 +86,7 @@
 		("range", builtin_range::INST),
 		("join", builtin_join::INST),
 		("lines", builtin_lines::INST),
+		("deepJoin", builtin_deep_join::INST),
 		("reverse", builtin_reverse::INST),
 		("any", builtin_any::INST),
 		("all", builtin_all::INST),
modifiedcrates/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