difftreelog
perf make std.substr builtin
in: master
2 files changed
crates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth81 ("objectFieldsEx".into(), builtin_object_fields_ex),81 ("objectFieldsEx".into(), builtin_object_fields_ex),82 ("objectHasEx".into(), builtin_object_has_ex),82 ("objectHasEx".into(), builtin_object_has_ex),83 ("slice".into(), builtin_slice),83 ("slice".into(), builtin_slice),84 ("substr".into(), builtin_substr),84 ("primitiveEquals".into(), builtin_primitive_equals),85 ("primitiveEquals".into(), builtin_primitive_equals),85 ("equals".into(), builtin_equals),86 ("equals".into(), builtin_equals),86 ("modulo".into(), builtin_modulo),87 ("modulo".into(), builtin_modulo),241 })242 })242}243}244245fn builtin_substr(context: Context, _loc: Option<&ExprLocation>, args: &ArgsDesc) -> Result<Val> {246 parse_args!(context, "substr", args, 3, [247 0, str: ty!(string) => Val::Str;248 1, from: ty!(BoundedNumber<(Some(0.0)), (None)>) => Val::Num;249 2, len: ty!(BoundedNumber<(Some(0.0)), (None)>) => Val::Num;250 ], {251 let out: String = str.chars().skip(from as usize).take(len as usize).collect();252 Ok(Val::Str(out.into()))253 })254}243255244fn builtin_primitive_equals(256fn builtin_primitive_equals(245 context: Context,257 context: Context,crates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/std.jsonnet
+++ b/crates/jrsonnet-stdlib/src/std.jsonnet
@@ -48,12 +48,7 @@
toString(a)::
if std.type(a) == 'string' then a else '' + a,
- substr(str, from, len)::
- assert std.isString(str) : 'substr first parameter should be a string, got ' + std.type(str);
- assert std.isNumber(from) : 'substr second parameter should be a string, got ' + std.type(from);
- assert std.isNumber(len) : 'substr third parameter should be a string, got ' + std.type(len);
- assert len >= 0 : 'substr third parameter should be greater than zero, got ' + len;
- std.join('', std.makeArray(std.max(0, std.min(len, std.length(str) - from)), function(i) str[i + from])),
+ substr:: $intrinsic(substr),
startsWith(a, b)::
if std.length(a) < std.length(b) then