difftreelog
perf(evaluator) faster std.base64
in: master
4 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -108,6 +108,7 @@
name = "jrsonnet-evaluator"
version = "1.0.0"
dependencies = [
+ "base64",
"bincode",
"closure",
"indexmap",
crates/jrsonnet-evaluator/Cargo.tomldiffbeforeafterboth1[package]2name = "jrsonnet-evaluator"3description = "jsonnet interpreter"4version = "1.0.0"5authors = ["Лач <iam@lach.pw>"]6license = "MIT"7edition = "2018"89# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html1011[features]12default = ["serialized-stdlib", "faster"]13# Serializes standard library AST instead of parsing them every run14serialized-stdlib = ["serde", "bincode", "jrsonnet-parser/deserialize"]15# Same as above, but with generated code instead of serde. Reduces memory usage, but increases binary size and compilation time16codegenerated-stdlib = []17# Replace some standard library functions with faster implementations (I.e manifestJsonEx)18# Library works fine without this feature, but requires more memory and time for std function calls19faster = []2021[dependencies]22jrsonnet-parser = { path = "../jrsonnet-parser", version = "1.0.0" }23closure = "0.3.0"24jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "1.0.0" }25indexmap = "1.4.0"26md5 = "0.7.0"2728serde = { version = "1.0.114", optional = true }29bincode = { version = "1.3.1", optional = true }3031[build-dependencies]32jrsonnet-parser = { path = "../jrsonnet-parser", features = ["dump", "serialize", "deserialize"], version = "1.0.0" }33jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "1.0.0" }34structdump = "0.1.2"35serde = "1.0.114"36bincode = "1.3.1"1[package]2name = "jrsonnet-evaluator"3description = "jsonnet interpreter"4version = "1.0.0"5authors = ["Лач <iam@lach.pw>"]6license = "MIT"7edition = "2018"89# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html1011[features]12default = ["serialized-stdlib", "faster"]13# Serializes standard library AST instead of parsing them every run14serialized-stdlib = ["serde", "bincode", "jrsonnet-parser/deserialize"]15# Same as above, but with generated code instead of serde. Reduces memory usage, but increases binary size and compilation time16codegenerated-stdlib = []17# Replace some standard library functions with faster implementations (I.e manifestJsonEx)18# Library works fine without this feature, but requires more memory and time for std function calls19faster = []2021[dependencies]22jrsonnet-parser = { path = "../jrsonnet-parser", version = "1.0.0" }23closure = "0.3.0"24jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "1.0.0" }25indexmap = "1.4.0"26md5 = "0.7.0"27base64 = "0.12.3"2829serde = { version = "1.0.114", optional = true }30bincode = { version = "1.3.1", optional = true }3132[build-dependencies]33jrsonnet-parser = { path = "../jrsonnet-parser", features = ["dump", "serialize", "deserialize"], version = "1.0.0" }34jrsonnet-stdlib = { path = "../jrsonnet-stdlib", version = "1.0.0" }35structdump = "0.1.2"36serde = "1.0.114"37bincode = "1.3.1"crates/jrsonnet-evaluator/build.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/build.rs
+++ b/crates/jrsonnet-evaluator/build.rs
@@ -35,7 +35,7 @@
Member::Field(FieldMember {
name: FieldName::Fixed(name),
..
- }) if **name == *"join" || **name == *"manifestJsonEx" || **name == *"escapeStringJson" || **name == *"equals"
+ }) if **name == *"join" || **name == *"manifestJsonEx" || **name == *"escapeStringJson" || **name == *"equals" || **name == *"base64"
)
})
.collect(),
crates/jrsonnet-evaluator/src/evaluate.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate.rs
@@ -566,6 +566,22 @@
Ok(Val::Str(format!("{:x}", md5::compute(&str.as_bytes())).into()))
}))?,
// faster
+ ("std", "base64") => parse_args!(context, "std.base64", args, 1, [
+ 0, input: [Val::Str | Val::Arr], vec![ValType::Arr, ValType::Str];
+ ], {
+ Val::Str(match input {
+ Val::Str(s) => {
+ base64::encode(s.bytes().collect::<Vec<_>>()).into()
+ },
+ Val::Arr(a) => {
+ base64::encode(a.iter().map(|v| {
+ Ok(v.clone().try_cast_num("base64 array")? as u8)
+ }).collect::<Result<Vec<_>>>()?).into()
+ },
+ _ => unreachable!()
+ })
+ }),
+ // faster
("std", "join") => noinline!(parse_args!(context, "std.join", args, 2, [
0, sep: [Val::Str|Val::Arr], vec![ValType::Str, ValType::Arr];
1, arr: [Val::Arr]!!Val::Arr, vec![ValType::Arr];