[naga] Use racy::OnceBox for Namer::default (#7517)

This commit is contained in:
Connor Fitzgerald 2025-04-11 14:12:25 -04:00 committed by GitHub
parent 27115f7d57
commit e45013645f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 4 deletions

1
Cargo.lock generated
View File

@ -2419,6 +2419,7 @@ dependencies = [
"itertools 0.13.0",
"log",
"num-traits",
"once_cell",
"petgraph 0.8.0",
"pp-rs",
"ron",

View File

@ -96,6 +96,7 @@ indexmap.workspace = true
log = "0.4"
# `half` requires 0.2.16 for `FromBytes` and `ToBytes`.
num-traits = { version = "0.2.16", default-features = false }
once_cell = { workspace = true, features = ["alloc", "race"] }
strum = { workspace = true, optional = true }
spirv = { version = "0.3", optional = true }
thiserror.workspace = true

View File

@ -1,11 +1,14 @@
use alloc::{
borrow::Cow,
boxed::Box,
format,
string::{String, ToString},
vec::Vec,
};
use core::hash::{Hash, Hasher};
use hashbrown::HashSet;
use once_cell::race::OnceBox;
use crate::{arena::Handle, FastHashMap, FastHashSet};
@ -46,15 +49,13 @@ pub struct Namer {
reserved_prefixes: Vec<&'static str>,
}
#[cfg(any(wgsl_out, glsl_out, msl_out, hlsl_out, test))]
impl Default for Namer {
fn default() -> Self {
use std::sync::LazyLock;
static DEFAULT_KEYWORDS: LazyLock<HashSet<&'static str>> = LazyLock::new(HashSet::default);
static DEFAULT_KEYWORDS: OnceBox<HashSet<&'static str>> = OnceBox::new();
Self {
unique: Default::default(),
keywords: &DEFAULT_KEYWORDS,
keywords: DEFAULT_KEYWORDS.get_or_init(|| Box::new(HashSet::default())),
keywords_case_insensitive: Default::default(),
reserved_prefixes: Default::default(),
}