git.delta.rocks / jrsonnet / refs/commits / be6d2bdf9187

difftreelog

perf(stdlib) remove allocation from std.base64

Yaroslav Bolyukin2022-11-20parent: #587f5b8.patch.diff
in: master

2 files changed

modifiedcrates/jrsonnet-stdlib/src/encoding.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/encoding.rs
+++ b/crates/jrsonnet-stdlib/src/encoding.rs
@@ -18,11 +18,11 @@
 }
 
 #[builtin]
-pub fn builtin_base64(input: Either![IBytes, IStr]) -> Result<String> {
+pub fn builtin_base64(input: Either![IStr, IBytes]) -> Result<String> {
 	use Either2::*;
 	Ok(match input {
-		A(a) => base64::encode(a.as_slice()),
-		B(l) => base64::encode(l.bytes().collect::<Vec<_>>()),
+		A(l) => base64::encode(l.as_bytes()),
+		B(a) => base64::encode(a.as_slice()),
 	})
 }
 
modifiedcrates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth
253 context.build()253 context.build()
254 },254 },
255 #[cfg(feature = "legacy-this-file")]255 #[cfg(feature = "legacy-this-file")]
256 stdlib_obj: stdlib_uncached(s, settings.clone()),256 stdlib_obj: stdlib_uncached(settings.clone()),
257 settings,257 settings,
258 }258 }
259 }259 }
319 .member("thisFile".into())319 .member("thisFile".into())
320 .hide()320 .hide()
321 .value(321 .value(Val::Str(match source.source_path().path() {
322 s,
323 Val::Str(match source.source_path().path() {
324 Some(p) => self.settings().path_resolver.resolve(p).into(),322 Some(p) => self.settings().path_resolver.resolve(p).into(),
325 None => source.source_path().to_string().into(),323 None => source.source_path().to_string().into(),
326 }),324 }))
327 )
328 .expect("this object builder is empty");325 .expect("this object builder is empty");
329 let stdlib_with_this_file = builder.build();326 let stdlib_with_this_file = builder.build();
330327
331 let mut context = ContextBuilder::with_capacity(1);328 let mut context = ContextBuilder::with_capacity(s, 1);
332 context.bind(329 context.bind(
333 "std".into(),330 "std".into(),
334 Thunk::evaluated(Val::Obj(stdlib_with_this_file)),331 Thunk::evaluated(Val::Obj(stdlib_with_this_file)),