Remove TinyList
.
It is optimized for lists with a single element, avoiding the need for an allocation in that case. But `SmallVec<[T; 1]>` also avoids the allocation, and is better in general: more standard, log2 number of allocations if the list exceeds one item, and a much more capable API. This commit removes `TinyList` and converts the two uses to `SmallVec<[T; 1]>`. It also reorders the `use` items in the relevant file so they are in just two sections (`pub` and non-`pub`), ordered alphabetically, instead of many sections. (This is a relevant part of the change because I had to decide where to add a `use` item for `SmallVec`.)
This commit is contained in:
parent
d7814e72eb
commit
f5d7d346a4
4 changed files with 8 additions and 245 deletions
|
@ -125,10 +125,11 @@ use std::io::{Read, Write};
|
|||
use std::num::NonZero;
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
|
||||
use rustc_ast::LitKind;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sync::{HashMapExt, Lock};
|
||||
use rustc_data_structures::tiny_list::TinyList;
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
|
||||
|
@ -266,8 +267,8 @@ type DecodingSessionId = NonZero<u32>;
|
|||
#[derive(Clone)]
|
||||
enum State {
|
||||
Empty,
|
||||
InProgressNonAlloc(TinyList<DecodingSessionId>),
|
||||
InProgress(TinyList<DecodingSessionId>, AllocId),
|
||||
InProgressNonAlloc(SmallVec<[DecodingSessionId; 1]>),
|
||||
InProgress(SmallVec<[DecodingSessionId; 1]>, AllocId),
|
||||
Done(AllocId),
|
||||
}
|
||||
|
||||
|
@ -337,8 +338,7 @@ impl<'s> AllocDecodingSession<'s> {
|
|||
// If this is an allocation, we need to reserve an
|
||||
// `AllocId` so we can decode cyclic graphs.
|
||||
let alloc_id = decoder.interner().reserve_alloc_id();
|
||||
*entry =
|
||||
State::InProgress(TinyList::new_single(self.session_id), alloc_id);
|
||||
*entry = State::InProgress(smallvec![self.session_id], alloc_id);
|
||||
Some(alloc_id)
|
||||
}
|
||||
AllocDiscriminant::Fn
|
||||
|
@ -346,8 +346,7 @@ impl<'s> AllocDecodingSession<'s> {
|
|||
| AllocDiscriminant::VTable => {
|
||||
// Fns and statics cannot be cyclic, and their `AllocId`
|
||||
// is determined later by interning.
|
||||
*entry =
|
||||
State::InProgressNonAlloc(TinyList::new_single(self.session_id));
|
||||
*entry = State::InProgressNonAlloc(smallvec![self.session_id]);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
@ -357,7 +356,7 @@ impl<'s> AllocDecodingSession<'s> {
|
|||
bug!("this should be unreachable");
|
||||
} else {
|
||||
// Start decoding concurrently.
|
||||
sessions.insert(self.session_id);
|
||||
sessions.push(self.session_id);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
@ -367,7 +366,7 @@ impl<'s> AllocDecodingSession<'s> {
|
|||
return alloc_id;
|
||||
} else {
|
||||
// Start decoding concurrently.
|
||||
sessions.insert(self.session_id);
|
||||
sessions.push(self.session_id);
|
||||
Some(alloc_id)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue