difftreelog
perf(stdlib) remove allocation from std.base64
in: master
2 files changed
crates/jrsonnet-stdlib/src/encoding.rsdiffbeforeafterboth18}18}191920#[builtin]20#[builtin]21pub fn builtin_base64(input: Either![IBytes, IStr]) -> Result<String> {21pub fn builtin_base64(input: Either![IStr, IBytes]) -> Result<String> {22 use Either2::*;22 use Either2::*;23 Ok(match input {23 Ok(match input {24 A(a) => base64::encode(a.as_slice()),24 A(l) => base64::encode(l.as_bytes()),25 B(l) => base64::encode(l.bytes().collect::<Vec<_>>()),25 B(a) => base64::encode(a.as_slice()),26 })26 })27}27}2828crates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -253,7 +253,7 @@
context.build()
},
#[cfg(feature = "legacy-this-file")]
- stdlib_obj: stdlib_uncached(s, settings.clone()),
+ stdlib_obj: stdlib_uncached(settings.clone()),
settings,
}
}
@@ -318,17 +318,14 @@
builder
.member("thisFile".into())
.hide()
- .value(
- s,
- Val::Str(match source.source_path().path() {
- Some(p) => self.settings().path_resolver.resolve(p).into(),
- None => source.source_path().to_string().into(),
- }),
- )
+ .value(Val::Str(match source.source_path().path() {
+ Some(p) => self.settings().path_resolver.resolve(p).into(),
+ None => source.source_path().to_string().into(),
+ }))
.expect("this object builder is empty");
let stdlib_with_this_file = builder.build();
- let mut context = ContextBuilder::with_capacity(1);
+ let mut context = ContextBuilder::with_capacity(s, 1);
context.bind(
"std".into(),
Thunk::evaluated(Val::Obj(stdlib_with_this_file)),