Skip to content

Commit e450136

Browse files
authored
[naga] Use racy::OnceBox for Namer::default (#7517)
1 parent 27115f7 commit e450136

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

Cargo.lock

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

naga/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ indexmap.workspace = true
9696
log = "0.4"
9797
# `half` requires 0.2.16 for `FromBytes` and `ToBytes`.
9898
num-traits = { version = "0.2.16", default-features = false }
99+
once_cell = { workspace = true, features = ["alloc", "race"] }
99100
strum = { workspace = true, optional = true }
100101
spirv = { version = "0.3", optional = true }
101102
thiserror.workspace = true

naga/src/proc/namer.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
use alloc::{
22
borrow::Cow,
3+
boxed::Box,
34
format,
45
string::{String, ToString},
56
vec::Vec,
67
};
78
use core::hash::{Hash, Hasher};
9+
810
use hashbrown::HashSet;
11+
use once_cell::race::OnceBox;
912

1013
use crate::{arena::Handle, FastHashMap, FastHashSet};
1114

@@ -46,15 +49,13 @@ pub struct Namer {
4649
reserved_prefixes: Vec<&'static str>,
4750
}
4851

49-
#[cfg(any(wgsl_out, glsl_out, msl_out, hlsl_out, test))]
5052
impl Default for Namer {
5153
fn default() -> Self {
52-
use std::sync::LazyLock;
53-
static DEFAULT_KEYWORDS: LazyLock<HashSet<&'static str>> = LazyLock::new(HashSet::default);
54+
static DEFAULT_KEYWORDS: OnceBox<HashSet<&'static str>> = OnceBox::new();
5455

5556
Self {
5657
unique: Default::default(),
57-
keywords: &DEFAULT_KEYWORDS,
58+
keywords: DEFAULT_KEYWORDS.get_or_init(|| Box::new(HashSet::default())),
5859
keywords_case_insensitive: Default::default(),
5960
reserved_prefixes: Default::default(),
6061
}

0 commit comments

Comments
 (0)