Skip to content

Commit f50c0cb

Browse files
committed
Replace lazy_static with OnceLock
1 parent 06872fe commit f50c0cb

File tree

6 files changed

+18
-23
lines changed

6 files changed

+18
-23
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ half = "2.3.1"
131131
hyper = "0.14"
132132
image = { version = "0.24", default-features = false }
133133
indent = "0.1"
134-
infer = "0.15" # infer MIME type by checking the magic number signature
134+
infer = "0.15" # infer MIME type by checking the magic number signature
135135
itertools = "0.11"
136136
js-sys = "0.3"
137-
lazy_static = "1.4"
137+
# No lazy_static - use `std::sync::OnceLock` or `once_cell` instead
138138
lz4_flex = "0.11"
139139
log = "0.4"
140140
log-once = "0.4"

crates/re_viewer_context/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ egui_tiles.workspace = true
3737
glam.workspace = true
3838
half.workspace = true
3939
itertools.workspace = true
40-
lazy_static.workspace = true
4140
macaw.workspace = true
4241
ndarray.workspace = true
4342
nohash-hasher.workspace = true

crates/re_viewer_context/src/annotations.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::{collections::BTreeMap, sync::Arc};
22

33
use ahash::HashMap;
4-
use lazy_static::lazy_static;
54
use nohash_hasher::IntSet;
65

76
use re_arrow_store::LatestAtQuery;
@@ -14,6 +13,8 @@ use re_types::datatypes::{AnnotationInfo, ClassDescription, ClassId, KeypointId}
1413
use super::{auto_color, ViewerContext};
1514
use crate::DefaultColor;
1615

16+
const MISSING_ROW_ID: RowId = RowId::ZERO;
17+
1718
#[derive(Clone, Debug)]
1819
pub struct Annotations {
1920
row_id: RowId,
@@ -29,6 +30,14 @@ impl Annotations {
2930
}
3031
}
3132

33+
/// Fast access to an [`Arc`] sharing the same [`Annotations::missing`] instance.
34+
pub fn missing_arc() -> Arc<Annotations> {
35+
use std::sync::OnceLock;
36+
static CELL: OnceLock<Arc<Annotations>> = OnceLock::new();
37+
CELL.get_or_init(|| Arc::new(Annotations::missing()))
38+
.clone()
39+
}
40+
3241
pub fn try_from_view(view: &ArchetypeView<AnnotationContext>) -> Option<Self> {
3342
re_tracing::profile_function!();
3443

@@ -273,7 +282,7 @@ impl AnnotationMap {
273282
}
274283

275284
// Search through the all prefixes of this entity path until we find a
276-
// matching annotation. If we find nothing return the default [`MISSING_ANNOTATIONS`].
285+
// matching annotation. If we find nothing return the default [`Annotations::missing_arc`].
277286
pub fn find(&self, entity_path: &EntityPath) -> Arc<Annotations> {
278287
let mut next_parent = Some(entity_path.clone());
279288
while let Some(parent) = next_parent {
@@ -285,14 +294,6 @@ impl AnnotationMap {
285294
}
286295

287296
// Otherwise return the missing legend
288-
Arc::clone(&MISSING_ANNOTATIONS)
297+
Annotations::missing_arc()
289298
}
290299
}
291-
292-
// ---
293-
294-
const MISSING_ROW_ID: RowId = RowId::ZERO;
295-
296-
lazy_static! {
297-
pub static ref MISSING_ANNOTATIONS: Arc<Annotations> = Arc::new(Annotations::missing());
298-
}

crates/re_viewer_context/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ pub mod gpu_bridge;
2424

2525
pub use annotations::{
2626
AnnotationMap, Annotations, ResolvedAnnotationInfo, ResolvedAnnotationInfos,
27-
MISSING_ANNOTATIONS,
2827
};
2928
pub use app_options::AppOptions;
3029
pub use blueprint_id::{DataQueryId, SpaceViewId};

crates/re_viewer_context/src/space_view/highlights.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use lazy_static::lazy_static;
21
use nohash_hasher::IntMap;
32

43
use re_log_types::EntityPathHash;
@@ -39,11 +38,6 @@ pub struct SpaceViewOutlineMasks {
3938
pub instances: ahash::HashMap<InstanceKey, OutlineMaskPreference>,
4039
}
4140

42-
lazy_static! {
43-
static ref SPACEVIEW_OUTLINE_MASK_NONE: SpaceViewOutlineMasks =
44-
SpaceViewOutlineMasks::default();
45-
}
46-
4741
impl SpaceViewOutlineMasks {
4842
pub fn index_outline_mask(&self, instance_key: InstanceKey) -> OutlineMaskPreference {
4943
self.instances
@@ -72,9 +66,12 @@ impl SpaceViewHighlights {
7266
}
7367

7468
pub fn entity_outline_mask(&self, entity_path_hash: EntityPathHash) -> &SpaceViewOutlineMasks {
69+
use std::sync::OnceLock;
70+
static CELL: OnceLock<SpaceViewOutlineMasks> = OnceLock::new();
71+
7572
self.outlines_masks
7673
.get(&entity_path_hash)
77-
.unwrap_or(&SPACEVIEW_OUTLINE_MASK_NONE)
74+
.unwrap_or_else(|| CELL.get_or_init(SpaceViewOutlineMasks::default))
7875
}
7976

8077
pub fn any_outlines(&self) -> bool {

0 commit comments

Comments
 (0)