Skip to content

Commit 524f322

Browse files
committed
Use a NonZeroU32 in SymbolMapGeneration.
This makes Option<SourceFilePatHHandle> more compact.
1 parent 477a90f commit 524f322

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

samply-symbols/src/generation.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
use std::sync::atomic::AtomicU32;
1+
use std::{
2+
num::NonZeroU32,
3+
sync::atomic::{AtomicU32, Ordering},
4+
};
25

36
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
4-
pub struct SymbolMapGeneration(pub(crate) u32);
7+
pub struct SymbolMapGeneration(pub(crate) NonZeroU32);
58

6-
static SYMBOL_MAP_GENERATION: AtomicU32 = AtomicU32::new(0);
9+
static SYMBOL_MAP_GENERATION: AtomicU32 = AtomicU32::new(1);
710

811
impl Default for SymbolMapGeneration {
912
fn default() -> Self {
@@ -13,6 +16,12 @@ impl Default for SymbolMapGeneration {
1316

1417
impl SymbolMapGeneration {
1518
pub fn new() -> Self {
16-
Self(SYMBOL_MAP_GENERATION.fetch_add(1, std::sync::atomic::Ordering::Relaxed))
19+
let next_nonzero_wrapping = loop {
20+
match NonZeroU32::new(SYMBOL_MAP_GENERATION.fetch_add(1, Ordering::Relaxed)) {
21+
Some(gen) => break gen,
22+
None => continue,
23+
}
24+
};
25+
Self(next_nonzero_wrapping)
1726
}
1827
}

0 commit comments

Comments
 (0)