Skip to content

Commit 3c3a26f

Browse files
authored
Replace types from once_cell with std alternatives (#3345)
`std::sync::OnceLock` is effectively the same as `once_cell::sync::OnceCell`, and because the MSRV is now 1.70 it can be used instead. `Lazy<T>` can also simply be replaced by a `OnceLock`, making the `once_cell` dependency unnecessary.
1 parent 7155fe3 commit 3c3a26f

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ simd_helpers = "0.1"
109109
wasm-bindgen = { version = "0.2.90", optional = true }
110110
nom = { version = "7.1.3", optional = true }
111111
new_debug_unreachable = "1.0.4"
112-
once_cell = "1.19.0"
113112
av1-grain = "0.2.3"
114113
serde-big-array = { version = "0.5.1", optional = true }
115114
profiling = { version = "1" }

src/bin/common.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use crate::stats::MetricsEnabled;
1313
use crate::{ColorPrimaries, MatrixCoefficients, TransferCharacteristics};
1414
use clap::{CommandFactory, Parser as Clap, Subcommand};
1515
use clap_complete::{generate, Shell};
16-
use once_cell::sync::Lazy;
1716
use rav1e::prelude::*;
1817
use scan_fmt::scan_fmt;
1918

@@ -22,6 +21,7 @@ use std::fs::File;
2221
use std::io;
2322
use std::io::prelude::*;
2423
use std::path::PathBuf;
24+
use std::sync::OnceLock;
2525

2626
pub mod built_info {
2727
// The file has been placed there by the build script.
@@ -258,29 +258,30 @@ pub struct CliOptions {
258258
pub command: Option<Commands>,
259259
}
260260

261+
static VERSION_STR: OnceLock<String> = OnceLock::new();
262+
static LONG_VERSION_STR: OnceLock<String> = OnceLock::new();
263+
261264
fn get_version() -> &'static str {
262-
static VERSION_STR: Lazy<String> = Lazy::new(|| {
265+
VERSION_STR.get_or_init(|| {
263266
format!(
264267
"{} ({})",
265268
rav1e::version::full(),
266269
// We cannot use `built_info::DEBUG` because that tells us if there are debug symbols,
267270
// not if there are optimizations.
268271
if cfg!(debug_assertions) { "debug" } else { "release" }
269272
)
270-
});
271-
&VERSION_STR
273+
})
272274
}
273275

274276
fn get_long_version() -> &'static str {
275-
static LONG_VERSION_STR: Lazy<String> = Lazy::new(|| {
277+
LONG_VERSION_STR.get_or_init(|| {
276278
let rustflags = env!("CARGO_ENCODED_RUSTFLAGS");
277279
let rustflags = if rustflags.trim().is_empty() {
278280
"(None)".to_string()
279281
} else {
280282
// Replace non-printable ASCII Unit Separator with whitespace
281283
rustflags.replace(0x1F as char, " ")
282284
};
283-
284285
format!(
285286
"{}\n{} {}\nCompiled CPU Features: {}\nRuntime Assembly Support: {}{}\nThreading: {}\nUnstable Features: {}\nCompiler Flags: {}",
286287
get_version(),
@@ -297,8 +298,7 @@ fn get_long_version() -> &'static str {
297298
if cfg!(feature = "unstable") { "Enabled" } else { "Disabled" },
298299
rustflags
299300
)
300-
});
301-
&LONG_VERSION_STR
301+
})
302302
}
303303

304304
#[derive(Subcommand)]
@@ -351,8 +351,7 @@ pub struct ParsedCliOptions {
351351
}
352352

353353
#[cfg(feature = "serialize")]
354-
static HELP_TEXT: once_cell::sync::OnceCell<String> =
355-
once_cell::sync::OnceCell::new();
354+
static HELP_TEXT: OnceLock<String> = OnceLock::new();
356355

357356
#[cfg(feature = "serialize")]
358357
fn build_speed_long_help() -> Option<&'static str> {

src/capi.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ pub unsafe extern fn rav1e_version_short() -> *const c_char {
397397
concat!(env!("CARGO_PKG_VERSION"), "\0").as_ptr() as *const c_char
398398
}
399399

400-
static FULL_VERSION_C: once_cell::sync::OnceCell<CString> =
401-
once_cell::sync::OnceCell::new();
400+
static FULL_VERSION_C: std::sync::OnceLock<CString> =
401+
std::sync::OnceLock::new();
402402

403403
/// Version information with the information
404404
/// provided by `git describe --tags`.

0 commit comments

Comments
 (0)