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.jsonnetdiffbeforeafterboth48 toString(a)::48 toString(a)::49 if std.type(a) == 'string' then a else '' + a,49 if std.type(a) == 'string' then a else '' + a,505051 substr(str, from, len)::51 substr:: $intrinsic(substr),52 assert std.isString(str) : 'substr first parameter should be a string, got ' + std.type(str);53 assert std.isNumber(from) : 'substr second parameter should be a string, got ' + std.type(from);54 assert std.isNumber(len) : 'substr third parameter should be a string, got ' + std.type(len);55 assert len >= 0 : 'substr third parameter should be greater than zero, got ' + len;56 std.join('', std.makeArray(std.max(0, std.min(len, std.length(str) - from)), function(i) str[i + from])),575258 startsWith(a, b)::53 startsWith(a, b)::59 if std.length(a) < std.length(b) then54 if std.length(a) < std.length(b) then