Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace types from once_cell with std::sync::OnceLock #3345

Merged
merged 2 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ simd_helpers = "0.1"
wasm-bindgen = { version = "0.2.90", optional = true }
nom = { version = "7.1.3", optional = true }
new_debug_unreachable = "1.0.4"
once_cell = "1.19.0"
av1-grain = "0.2.3"
serde-big-array = { version = "0.5.1", optional = true }
profiling = { version = "1" }
Expand Down
19 changes: 9 additions & 10 deletions src/bin/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::stats::MetricsEnabled;
use crate::{ColorPrimaries, MatrixCoefficients, TransferCharacteristics};
use clap::{CommandFactory, Parser as Clap, Subcommand};
use clap_complete::{generate, Shell};
use once_cell::sync::Lazy;
use rav1e::prelude::*;
use scan_fmt::scan_fmt;

Expand All @@ -22,6 +21,7 @@ use std::fs::File;
use std::io;
use std::io::prelude::*;
use std::path::PathBuf;
use std::sync::OnceLock;

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

static VERSION_STR: OnceLock<String> = OnceLock::new();
static LONG_VERSION_STR: OnceLock<String> = OnceLock::new();

fn get_version() -> &'static str {
static VERSION_STR: Lazy<String> = Lazy::new(|| {
VERSION_STR.get_or_init(|| {
format!(
"{} ({})",
rav1e::version::full(),
// We cannot use `built_info::DEBUG` because that tells us if there are debug symbols,
// not if there are optimizations.
if cfg!(debug_assertions) { "debug" } else { "release" }
)
});
&VERSION_STR
})
}

fn get_long_version() -> &'static str {
static LONG_VERSION_STR: Lazy<String> = Lazy::new(|| {
LONG_VERSION_STR.get_or_init(|| {
let rustflags = env!("CARGO_ENCODED_RUSTFLAGS");
let rustflags = if rustflags.trim().is_empty() {
"(None)".to_string()
} else {
// Replace non-printable ASCII Unit Separator with whitespace
rustflags.replace(0x1F as char, " ")
};

format!(
"{}\n{} {}\nCompiled CPU Features: {}\nRuntime Assembly Support: {}{}\nThreading: {}\nUnstable Features: {}\nCompiler Flags: {}",
get_version(),
Expand All @@ -297,8 +298,7 @@ fn get_long_version() -> &'static str {
if cfg!(feature = "unstable") { "Enabled" } else { "Disabled" },
rustflags
)
});
&LONG_VERSION_STR
})
}

#[derive(Subcommand)]
Expand Down Expand Up @@ -351,8 +351,7 @@ pub struct ParsedCliOptions {
}

#[cfg(feature = "serialize")]
static HELP_TEXT: once_cell::sync::OnceCell<String> =
once_cell::sync::OnceCell::new();
static HELP_TEXT: OnceLock<String> = OnceLock::new();

#[cfg(feature = "serialize")]
fn build_speed_long_help() -> Option<&'static str> {
Expand Down
4 changes: 2 additions & 2 deletions src/capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ pub unsafe extern fn rav1e_version_short() -> *const c_char {
concat!(env!("CARGO_PKG_VERSION"), "\0").as_ptr() as *const c_char
}

static FULL_VERSION_C: once_cell::sync::OnceCell<CString> =
once_cell::sync::OnceCell::new();
static FULL_VERSION_C: std::sync::OnceLock<CString> =
std::sync::OnceLock::new();

/// Version information with the information
/// provided by `git describe --tags`.
Expand Down
Loading