11//! Implement thread-local storage.
22
33use 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
67use 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