Skip to content

Commit 9dedaae

Browse files
committed
LifeGuard::new takes &str instead of String
1 parent 520cdf9 commit 9dedaae

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

wgpu-core/src/command/bundle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
10261026
},
10271027
used: state.trackers,
10281028
context: bundle_encoder.context,
1029-
life_guard: LifeGuard::new(desc.label.to_string_or_default()),
1029+
life_guard: LifeGuard::new(desc.label.borrow_or_default()),
10301030
}
10311031
};
10321032

wgpu-core/src/device/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ impl<B: GfxBackend> Device<B> {
274274
desc_allocator: Mutex::new(descriptors),
275275
queue_group,
276276
#[cfg(debug_assertions)]
277-
life_guard: LifeGuard::new("<device>".to_string()),
277+
life_guard: LifeGuard::new("<device>"),
278278
#[cfg(not(debug_assertions))]
279-
life_guard: LifeGuard::new(String::new()),
279+
life_guard: LifeGuard::new(""),
280280
active_submission_index: 0,
281281
trackers: Mutex::new(TrackerSet::new(B::VARIANT)),
282282
render_passes: Mutex::new(FastHashMap::default()),
@@ -492,7 +492,7 @@ impl<B: GfxBackend> Device<B> {
492492
full_range: (),
493493
sync_mapped_writes: None,
494494
map_state: resource::BufferMapState::Idle,
495-
life_guard: LifeGuard::new(desc.label.to_string_or_default()),
495+
life_guard: LifeGuard::new(desc.label.borrow_or_default()),
496496
})
497497
}
498498

@@ -584,7 +584,7 @@ impl<B: GfxBackend> Device<B> {
584584
levels: 0..desc.mip_level_count as hal::image::Level,
585585
layers: 0..kind.num_layers(),
586586
},
587-
life_guard: LifeGuard::new(desc.label.to_string_or_default()),
587+
life_guard: LifeGuard::new(desc.label.borrow_or_default()),
588588
})
589589
}
590590

@@ -827,7 +827,7 @@ impl<B: GfxBackend> Device<B> {
827827
value: id::Valid(self_id),
828828
ref_count: self.life_guard.add_ref(),
829829
},
830-
life_guard: LifeGuard::new(desc.label.to_string_or_default()),
830+
life_guard: LifeGuard::new(desc.label.borrow_or_default()),
831831
bind_group_layout_ids: desc
832832
.bind_group_layouts
833833
.iter()
@@ -1596,7 +1596,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
15961596
extent: texture.kind.extent().at_level(desc.base_mip_level as _),
15971597
samples: texture.kind.num_samples(),
15981598
selector,
1599-
life_guard: LifeGuard::new(desc.label.to_string_or_default()),
1599+
life_guard: LifeGuard::new(desc.label.borrow_or_default()),
16001600
};
16011601
let ref_count = view.life_guard.add_ref();
16021602

@@ -1756,7 +1756,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
17561756
value: id::Valid(device_id),
17571757
ref_count: device.life_guard.add_ref(),
17581758
},
1759-
life_guard: LifeGuard::new(desc.label.to_string_or_default()),
1759+
life_guard: LifeGuard::new(desc.label.borrow_or_default()),
17601760
comparison: info.comparison.is_some(),
17611761
};
17621762
let ref_count = sampler.life_guard.add_ref();
@@ -2423,7 +2423,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
24232423
ref_count: device.life_guard.add_ref(),
24242424
},
24252425
layout_id: id::Valid(desc.layout),
2426-
life_guard: LifeGuard::new(desc.label.to_string_or_default()),
2426+
life_guard: LifeGuard::new(desc.label.borrow_or_default()),
24272427
used,
24282428
dynamic_binding_info,
24292429
};
@@ -3194,7 +3194,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
31943194
flags,
31953195
index_format: desc.vertex_state.index_format,
31963196
vertex_strides,
3197-
life_guard: LifeGuard::new(desc.label.to_string_or_default()),
3197+
life_guard: LifeGuard::new(desc.label.borrow_or_default()),
31983198
};
31993199

32003200
let id = hub
@@ -3418,7 +3418,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
34183418
value: id::Valid(device_id),
34193419
ref_count: device.life_guard.add_ref(),
34203420
},
3421-
life_guard: LifeGuard::new(desc.label.to_string_or_default()),
3421+
life_guard: LifeGuard::new(desc.label.borrow_or_default()),
34223422
};
34233423
let id = hub
34243424
.compute_pipelines
@@ -3624,9 +3624,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
36243624

36253625
let swap_chain = swap_chain::SwapChain {
36263626
#[cfg(debug_assertions)]
3627-
life_guard: LifeGuard::new("<SwapChain>".to_string()),
3627+
life_guard: LifeGuard::new("<SwapChain>"),
36283628
#[cfg(not(debug_assertions))]
3629-
life_guard: LifeGuard::new(String::new()),
3629+
life_guard: LifeGuard::new(""),
36303630
device_id: Stored {
36313631
value: id::Valid(device_id),
36323632
ref_count: device.life_guard.add_ref(),

wgpu-core/src/instance.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ impl<B: hal::Backend> Adapter<B> {
225225
features,
226226
limits,
227227
#[cfg(debug_assertions)]
228-
life_guard: LifeGuard::new("<Adapter>".to_string()),
228+
life_guard: LifeGuard::new("<Adapter>"),
229229
#[cfg(not(debug_assertions))]
230-
life_guard: LifeGuard::new(String::new()),
230+
life_guard: LifeGuard::new(""),
231231
}
232232
}
233233
}

wgpu-core/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ pub type Label<'a> = Option<Cow<'a, str>>;
6060

6161
trait LabelHelpers<'a> {
6262
fn to_string_or_default(&'a self) -> String;
63+
fn borrow_or_default(&'a self) -> &'a str;
6364
}
6465
impl<'a> LabelHelpers<'a> for Label<'a> {
66+
fn borrow_or_default(&'a self) -> &'a str {
67+
self.as_ref().map(|cow| cow.as_ref()).unwrap_or("")
68+
}
6569
fn to_string_or_default(&'a self) -> String {
6670
self.as_ref()
6771
.map(|cow| cow.as_ref())
@@ -184,13 +188,13 @@ pub struct LifeGuard {
184188

185189
impl LifeGuard {
186190
#[allow(unused_variables)]
187-
fn new(label: String) -> Self {
191+
fn new(label: &str) -> Self {
188192
let bx = Box::new(AtomicUsize::new(1));
189193
Self {
190194
ref_count: ptr::NonNull::new(Box::into_raw(bx)).map(RefCount),
191195
submission_index: AtomicUsize::new(0),
192196
#[cfg(debug_assertions)]
193-
label,
197+
label: label.to_string(),
194198
}
195199
}
196200

wgpu-core/src/swap_chain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
192192
levels: 0..1,
193193
},
194194
#[cfg(debug_assertions)]
195-
life_guard: LifeGuard::new("<SwapChain View>".to_string()),
195+
life_guard: LifeGuard::new("<SwapChain View>"),
196196
#[cfg(not(debug_assertions))]
197-
life_guard: LifeGuard::new(String::new()),
197+
life_guard: LifeGuard::new(""),
198198
};
199199

200200
let ref_count = view.life_guard.add_ref();

0 commit comments

Comments
 (0)