From 5faf7c9d7b5fcf8fb2795b5879aece45d7c62b21 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 13 Oct 2024 13:19:07 +0300 Subject: refactor(tvix/nix-compat): remove use of lazy_static This is now supported in the standard library via std::sync::LazyLock, but requires some manual shuffling around of code. I found at least one dead variable along the way, which I deleted. Change-Id: I8600c87c49078fb5ff72671994c77b919259e67b Reviewed-on: https://cl.tvl.fyi/c/depot/+/12608 Reviewed-by: flokli Tested-by: BuildkiteCI Autosubmit: tazjin --- tvix/nix-compat/benches/narinfo_parse.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'tvix/nix-compat/benches') diff --git a/tvix/nix-compat/benches/narinfo_parse.rs b/tvix/nix-compat/benches/narinfo_parse.rs index f35ba8468a88..ee2665a310d3 100644 --- a/tvix/nix-compat/benches/narinfo_parse.rs +++ b/tvix/nix-compat/benches/narinfo_parse.rs @@ -1,8 +1,9 @@ +use std::sync::LazyLock; +use std::{io, str}; + use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput}; -use lazy_static::lazy_static; use mimalloc::MiMalloc; use nix_compat::narinfo::NarInfo; -use std::{io, str}; #[global_allocator] static GLOBAL: MiMalloc = MiMalloc; @@ -19,18 +20,16 @@ Deriver: 2ch8jx910qk6721mp4yqsmvdfgj5c8ir-banking-0.3.0.drv Sig: cache.nixos.org-1:xcL67rBZPcdVZudDLpLeddkBa0KaFTw5A0udnaa0axysjrQ6Nvd9p3BLZ4rhKgl52/cKiU3c6aq60L8+IcE5Dw== "#; -lazy_static! { - static ref CASES: &'static [&'static str] = { - let data = - zstd::decode_all(io::Cursor::new(include_bytes!("../testdata/narinfo.zst"))).unwrap(); - let data = str::from_utf8(Vec::leak(data)).unwrap(); - Vec::leak( - data.split_inclusive("\n\n") - .map(|s| s.strip_suffix('\n').unwrap()) - .collect::>(), - ) - }; -} +static CASES: LazyLock<&'static [&'static str]> = LazyLock::new(|| { + let data = + zstd::decode_all(io::Cursor::new(include_bytes!("../testdata/narinfo.zst"))).unwrap(); + let data = str::from_utf8(Vec::leak(data)).unwrap(); + Vec::leak( + data.split_inclusive("\n\n") + .map(|s| s.strip_suffix('\n').unwrap()) + .collect::>(), + ) +}); pub fn parse(c: &mut Criterion) { let mut g = c.benchmark_group("parse"); -- cgit 1.4.1