Skip to content

Commit 0e052ab

Browse files
author
Vytautas Astrauskas
committed
Use Entry API in set_dtors_running.
1 parent 46b0317 commit 0e052ab

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/shims/tls.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! Implement thread-local storage.
22
33
use std::collections::BTreeMap;
4-
use std::collections::btree_map::Entry;
4+
use std::collections::btree_map::Entry as BTreeEntry;
5+
use std::collections::hash_map::Entry as HashMapEntry;
56

67
use log::trace;
78

@@ -186,15 +187,15 @@ impl<'tcx> TlsData<'tcx> {
186187
thread_local.range_mut((start, Unbounded))
187188
{
188189
match data.entry(thread_id) {
189-
Entry::Occupied(entry) => {
190+
BTreeEntry::Occupied(entry) => {
190191
if let Some(dtor) = dtor {
191192
// Set TLS data to NULL, and call dtor with old value.
192193
let data_scalar = entry.remove();
193194
let ret = Some((*dtor, data_scalar, key));
194195
return ret;
195196
}
196197
}
197-
Entry::Vacant(_) => {}
198+
BTreeEntry::Vacant(_) => {}
198199
}
199200
}
200201
None
@@ -204,16 +205,14 @@ impl<'tcx> TlsData<'tcx> {
204205
/// the existing values stored in `dtors_running` for this thread. Returns
205206
/// `true` if dtors for `thread` are already running.
206207
fn set_dtors_running_for_thread(&mut self, thread: ThreadId) -> bool {
207-
if self.dtors_running.contains_key(&thread) {
208-
true
209-
} else {
210-
// We need to guard this `insert` with a check because otherwise we
211-
// would risk to overwrite `last_dtor_key` with `None`.
212-
self.dtors_running.insert(
213-
thread,
214-
RunningDtorsState { last_dtor_key: None }
215-
);
216-
false
208+
match self.dtors_running.entry(thread) {
209+
HashMapEntry::Occupied(_) => true,
210+
HashMapEntry::Vacant(entry) => {
211+
// We cannot just do `self.dtors_running.insert` because that
212+
// would overwrite `last_dtor_key` with `None`.
213+
entry.insert(RunningDtorsState { last_dtor_key: None });
214+
false
215+
}
217216
}
218217
}
219218

0 commit comments

Comments
 (0)