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
18}18}
1919
20#[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}
2828
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)),