difftreelog
perf move std.lines 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
@@ -201,6 +201,14 @@
}
#[builtin]
+pub fn builtin_lines(arr: ArrValue) -> Result<IndexableVal> {
+ 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()
}
crates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth--- 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),
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 lines(arr)::15 std.join('\n', arr + ['']),1617 deepJoin(arr)::18 if std.isString(arr) then19 arr20 else if std.isArray(arr) then21 std.join('', [std.deepJoin(x) for x in arr])22 else23 error 'Expected string or array, got %s' % std.type(arr),2425 assertEqual(a, b)::26 if a == b then27 true28 else29 error 'Assertion failed. ' + a + ' != ' + b,3031 manifestIni(ini)::32 local body_lines(body) =33 std.join([], [34 local value_or_values = body[k];35 if std.isArray(value_or_values) then36 ['%s = %s' % [k, value] for value in value_or_values]37 else38 ['%s = %s' % [k, value_or_values]]3940 for k in std.objectFields(body)41 ]);4243 local section_lines(sname, sbody) = ['[%s]' % [sname]] + body_lines(sbody),44 main_body = if std.objectHas(ini, 'main') then body_lines(ini.main) else [],45 all_sections = [46 section_lines(k, ini.sections[k])47 for k in std.objectFields(ini.sections)48 ];49 std.join('\n', main_body + std.flattenArrays(all_sections) + ['']),5051 mergePatch(target, patch)::52 if std.isObject(patch) then53 local target_object =54 if std.isObject(target) then target else {};5556 local target_fields =57 if std.isObject(target_object) then std.objectFields(target_object) else [];5859 local null_fields = [k for k in std.objectFields(patch) if patch[k] == null];60 local both_fields = std.setUnion(target_fields, std.objectFields(patch));6162 {63 [k]:64 if !std.objectHas(patch, k) then65 target_object[k]66 else if !std.objectHas(target_object, k) then67 std.mergePatch(null, patch[k]) tailstrict68 else69 std.mergePatch(target_object[k], patch[k]) tailstrict70 for k in std.setDiff(both_fields, null_fields)71 }72 else73 patch,7475 resolvePath(f, r)::76 local arr = std.split(f, '/');77 std.join('/', std.makeArray(std.length(arr) - 1, function(i) arr[i]) + [r]),7879 find(value, arr)::80 if !std.isArray(arr) then81 error 'find second parameter should be an array, got ' + std.type(arr)82 else83 std.filter(function(i) arr[i] == value, std.range(0, std.length(arr) - 1)),84}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) },1314 deepJoin(arr)::15 if std.isString(arr) then16 arr17 else if std.isArray(arr) then18 std.join('', [std.deepJoin(x) for x in arr])19 else20 error 'Expected string or array, got %s' % std.type(arr),2122 assertEqual(a, b)::23 if a == b then24 true25 else26 error 'Assertion failed. ' + a + ' != ' + b,2728 manifestIni(ini)::29 local body_lines(body) =30 std.join([], [31 local value_or_values = body[k];32 if std.isArray(value_or_values) then33 ['%s = %s' % [k, value] for value in value_or_values]34 else35 ['%s = %s' % [k, value_or_values]]3637 for k in std.objectFields(body)38 ]);3940 local section_lines(sname, sbody) = ['[%s]' % [sname]] + body_lines(sbody),41 main_body = if std.objectHas(ini, 'main') then body_lines(ini.main) else [],42 all_sections = [43 section_lines(k, ini.sections[k])44 for k in std.objectFields(ini.sections)45 ];46 std.join('\n', main_body + std.flattenArrays(all_sections) + ['']),4748 mergePatch(target, patch)::49 if std.isObject(patch) then50 local target_object =51 if std.isObject(target) then target else {};5253 local target_fields =54 if std.isObject(target_object) then std.objectFields(target_object) else [];5556 local null_fields = [k for k in std.objectFields(patch) if patch[k] == null];57 local both_fields = std.setUnion(target_fields, std.objectFields(patch));5859 {60 [k]:61 if !std.objectHas(patch, k) then62 target_object[k]63 else if !std.objectHas(target_object, k) then64 std.mergePatch(null, patch[k]) tailstrict65 else66 std.mergePatch(target_object[k], patch[k]) tailstrict67 for k in std.setDiff(both_fields, null_fields)68 }69 else70 patch,7172 resolvePath(f, r)::73 local arr = std.split(f, '/');74 std.join('/', std.makeArray(std.length(arr) - 1, function(i) arr[i]) + [r]),7576 find(value, arr)::77 if !std.isArray(arr) then78 error 'find second parameter should be an array, got ' + std.type(arr)79 else80 std.filter(function(i) arr[i] == value, std.range(0, std.length(arr) - 1)),81}