difftreelog
perf move resolvePath 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
@@ -208,6 +208,14 @@
)
}
+#[builtin]
+pub fn builtin_resolve_path(f: String, r: String) -> String {
+ let Some(pos) = f.rfind('/') else {
+ return r;
+ };
+ format!("{}{}", &f[..=pos], r)
+}
+
pub fn deep_join_inner(out: &mut String, arr: IndexableVal) -> Result<()> {
use std::fmt::Write;
match arr {
crates/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),
+ ("resolvePath", builtin_resolve_path::INST),
("deepJoin", builtin_deep_join::INST),
("reverse", builtin_reverse::INST),
("any", builtin_any::INST),
crates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth1{2 local std = self,34 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) },1314 resolvePath(f, r)::15 local arr = std.split(f, '/');16 std.join('/', std.makeArray(std.length(arr) - 1, function(i) arr[i]) + [r]),17}1{2 local std = self,34 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}