1
1
//! Implement thread-local storage.
2
2
3
3
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 ;
5
6
6
7
use log:: trace;
7
8
@@ -186,15 +187,15 @@ impl<'tcx> TlsData<'tcx> {
186
187
thread_local. range_mut ( ( start, Unbounded ) )
187
188
{
188
189
match data. entry ( thread_id) {
189
- Entry :: Occupied ( entry) => {
190
+ BTreeEntry :: Occupied ( entry) => {
190
191
if let Some ( dtor) = dtor {
191
192
// Set TLS data to NULL, and call dtor with old value.
192
193
let data_scalar = entry. remove ( ) ;
193
194
let ret = Some ( ( * dtor, data_scalar, key) ) ;
194
195
return ret;
195
196
}
196
197
}
197
- Entry :: Vacant ( _) => { }
198
+ BTreeEntry :: Vacant ( _) => { }
198
199
}
199
200
}
200
201
None
@@ -204,16 +205,14 @@ impl<'tcx> TlsData<'tcx> {
204
205
/// the existing values stored in `dtors_running` for this thread. Returns
205
206
/// `true` if dtors for `thread` are already running.
206
207
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
+ }
217
216
}
218
217
}
219
218
0 commit comments