Skip to content

Commit

Permalink
perf: move resolvePath to native
Browse files Browse the repository at this point in the history
  • Loading branch information
CertainLach committed May 19, 2024
1 parent ec89bf2 commit b5ab57d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 8 additions & 0 deletions crates/jrsonnet-stdlib/src/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ pub fn builtin_lines(arr: ArrValue) -> Result<IndexableVal> {
)
}

#[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 {
Expand Down
1 change: 1 addition & 0 deletions crates/jrsonnet-stdlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub fn stdlib_uncached(settings: Rc<RefCell<Settings>>) -> ObjValue {
("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),
Expand Down
4 changes: 0 additions & 4 deletions crates/jrsonnet-stdlib/src/std.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@
error ('std.mapWithKey second param must be object, got ' + std.type(obj))
else
{ [k]: func(k, obj[k]) for k in std.objectFields(obj) },

resolvePath(f, r)::
local arr = std.split(f, '/');
std.join('/', std.makeArray(std.length(arr) - 1, function(i) arr[i]) + [r]),
}

0 comments on commit b5ab57d

Please sign in to comment.